我正在尝试将Slick Slider添加到网站,并且该网站正在运行,但没有响应。在手机上查看时,它保持为四列。
<script src="//cdn.shopify.com/s/files/1/0070/9971/1557/t/9/assets/slick.min.js?v=7177913489436168581" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.featured-slider').slick({
dots: true,
infinite: true,
speed: 300,
slidesToShow: 4,
slidesToScroll: 1,
prevArrow: '<button type="button" class="slick-prev"><img src="//cdn.shopify.com/s/files/1/0070/9971/1557/t/9/assets/icon-left.svg?v=1916513632564042252"></button>',
nextArrow: '<button type="button" class="slick-next"><img src="//cdn.shopify.com/s/files/1/0070/9971/1557/t/9/assets/icon-right.svg?v=6098146811289990150"></button>',
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 4,
slidesToScroll: 1,
infinite: true,
dots: false
}
},
{
breakpoint: 600,
settings: {
slidesToShow: 2,
slidesToScroll: 1
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
// You can unslick at a given breakpoint now by adding:
// settings: "unslick"
// instead of a settings object
]
});
});
</script>
如您所见,这是一个shopify网站,它不会在控制台中产生任何错误,但是经过大量测试,我发现一些javascript似乎打破了滑动滑块的响应能力。一个Jquery插件,称为节流/去抖动...看起来像这样...
/*
* jQuery throttle / debounce - v1.1 - 3/7/2010
* http://benalman.com/projects/jquery-throttle-debounce-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
function(e,t){var n,i=e.jQuery||e.Cowboy||(e.Cowboy={});i.throttle=n=function(e,n,o,r){function s(){function i(){l=+new Date,o.apply(u,d)}function s(){a=t}var u=this,c=+new Date-l,d=arguments;r&&!a&&i(),a&&clearTimeout(a),r===t&&c>e?i():n!==!0&&(a=setTimeout(r?s:i,r===t?e-c:e))}var a,l=0;return"boolean"!=typeof n&&(r=o,o=n,n=t),i.guid&&(s.guid=o.guid=o.guid||i.guid++),s},i.debounce=function(e,i,o){return o===t?n(e,i,!1):n(e,o,i!==!1)}}(this);
当我删除上面的代码时,光滑的滑块响应能力非常好。我无法删除上面的代码,因为这样做会破坏网站的其他部分。任何人都知道有没有办法让上面的jquery插件保持适当状态,从而使响应变得更加流畅?