gpt4 book ai didi

javascript - 尝试使用 Shuffle.js 但出现 Uncaught TypeError : Shuffle is not a constructor

转载 作者:行者123 更新时间:2023-12-03 05:48:05 41 4
gpt4 key购买 nike

对于那些了解情况的人来说,这应该是一个足够简单的问题 - 为什么我会在控制台中收到此错误?我尝试按照 Shuffle homepage 上“用法”下显示的代码进行操作但我认为该页面忽略了包含开始使用该库的所有步骤。

这是我的索引文件中的代码,该文件位于安装库时创建的 shufflejs 文件夹中。

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Shuffle Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
</head>

<body>
<div id="grid" class="row my-shuffle-container">
<figure class="col-4@sm picture-item" data-groups='["photography"]' data-date-created="2010-09-14" data-title="Baseball">
<div class="aspect aspect--16x9">
<div class="aspect__inner">
<img src="/img/baseball.png" alt="" height="145" width="230">
</div>
</div>
<figcaption>Baseball</figcaption>
</figure>
<figure class="col-4@sm picture-item" data-groups='["wallpaper","3d"]' data-date-created="2011-08-14" data-title="Tennis">
<div class="aspect aspect--16x9">
<div class="aspect__inner">
<img src="/img/tennis-ball.png" alt="" height="145" width="230">
</div>
</div>
<figcaption>Tennis</figcaption>
</figure>
<figure class="col-4@sm picture-item" data-groups='["wallpaper","3d"]' data-date-created="2009-05-27" data-title="iMac">
<div class="aspect aspect--16x9">
<div class="aspect__inner">
<img src="/img/imac.png" alt="" height="145" width="230">
</div>
</div>
<figcaption>iMac</figcaption>
</figure>
<div class="col-1@sm my-sizer-element"></div>
</div>

<script>
var Shuffle = window.shuffle;
var element = document.getElementById('grid');
var sizer = element.querySelector('.my-sizer-element');

var shuffle = new Shuffle(element, {
itemSelector: '.picture-item',
sizer: sizer // could also be a selector: '.my-sizer-element'
});
// Overrideable options
Shuffle.options = {
group: Shuffle.ALL_ITEMS, // Initial filter group.
speed: 250, // Transition/animation speed (milliseconds).
easing: 'ease', // CSS easing function to use.
itemSelector: '*', // e.g. '.picture-item'.
sizer: null, // Element or selector string. Use an element to determine the size of columns and gutters.
gutterWidth: 0, // A static number or function that tells the plugin how wide the gutters between columns are (in pixels).
columnWidth: 0, // A static number or function that returns a number which tells the plugin how wide the columns are (in pixels).
delimeter: null, // If your group is not json, and is comma delimeted, you could set delimeter to ','.
buffer: 0, // Useful for percentage based heights when they might not always be exactly the same (in pixels).
columnThreshold: 0.01, // Reading the width of elements isn't precise enough and can cause columns to jump between values.
initialSort: null, // Shuffle can be initialized with a sort object. It is the same object given to the sort method.
throttle: throttle, // By default, shuffle will throttle resize events. This can be changed or removed.
throttleTime: 300, // How often shuffle can be called on resize (in milliseconds).
staggerAmount: 15, // Transition delay offset for each item in milliseconds.
staggerAmountMax: 250, // Maximum stagger delay in milliseconds.
useTransforms: true, // Whether to use transforms or absolute positioning.
};
</script>
</body>
</html>

最佳答案

我遇到了同样的问题,并通过将 shuffle.min.js 添加到我的文件而不是使用 CDN 来修复它。它仅使用:

var Shuffle = window.Shuffle;
var el = document.querySelector('#shuffle');
var shuffleInstance = new Shuffle(el,{
itemSelector: '.item'
});

我希望这会有所帮助。

关于javascript - 尝试使用 Shuffle.js 但出现 Uncaught TypeError : Shuffle is not a constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40251255/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com