jQuery SlickJS,unslick() 删除问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27276119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SlickJS, unslick() remove issue
提问by hungrysquirrel
Good Afternoon,
下午好,
I'm currently working and using SlickJS Carousel, I'm trying to remove several items when the window width is larger than 375 using the unslick();
snippet.
我目前正在工作并使用SlickJS Carousel,当窗口宽度大于 375 时,我正在尝试使用unslick();
代码段删除几个项目。
I can see the resize function working as when the window size is less than 375 the slick();
carousel display without any issues.
我可以看到调整大小功能在窗口大小小于 375 时,slick();
轮播显示没有任何问题。
If anyone can see whats going wrong please let me know.
如果有人能看到出了什么问题,请告诉我。
Thank you.
谢谢你。
JS
JS
$(document).ready(function () {
// Header Slider
$('.touchslider_one').slick({
autoplay: true,
infinite: true,
speed: 1500,
autoplaySpeed: 3000,
dots: false,
slidesToShow: 1,
slidesToScroll: 1,
fade: true,
cssEase: 'linear',
});
onresize();
$(window).resize(function () {
onresize();
});
});
function onresize(){
checkWidth();
}
function checkWidth() {
if ($(window).width() < 376 ) {
// Boxes
$('.touchslider_fourth').slick({
autoplay: false,
infinite: true,
speed: 1500,
adaptiveHeight: true,
dots: false,
slidesToShow: 1,
slidesToScroll: 1,
cssEase: 'linear'
});
// Featured Products
$('.touchslider_three').slick({
autoplay: false,
infinite: true,
speed: 1500,
adaptiveHeight: true,
dots: false,
slidesToShow: 1,
slidesToScroll: 1,
cssEase: 'linear'
});
// Logos
$('.touchslider_two').unslick();
$('.touchslider_two').slick({
autoplay: true,
infinite: true,
speed: 1500,
autoplaySpeed: 6000,
dots: false,
slidesToShow: 1,
slidesToScroll: 1,
cssEase: 'linear'
});
} else {
// Test
console.log('Larger than 375');
// Remove
$('.touchslider_fourth').unslick();
$('.touchslider_three').unslick();
$('.touchslider_two').unslick();
// Rebuild
$('.touchslider_two').slick({
autoplay: true,
infinite: true,
speed: 1500,
autoplaySpeed: 6000,
dots: false,
slidesToShow: 5,
slidesToScroll: 5,
cssEase: 'linear'
});
}
}
回答by hungrysquirrel
Try this:
尝试这个:
$('.your-slider').slick('unslick');
回答by hungrysquirrel
After talking with Ken Wheelerand reading through a couple Githubissues it looked like wtranhad the answer I was looking for, Although I had to tweak to match my requirements it pretty much worked first time around.
在与Ken Wheeler交谈并阅读了几个Github问题后,wtran似乎找到了我正在寻找的答案,虽然我必须调整以符合我的要求,但它在第一次几乎可以正常工作。
I'm now able to trigger unslick();
when the window resizes over a specific width and rebuild the carousel if the window resizes less than the specific width.
我现在可以unslick();
在窗口调整大小超过特定宽度时触发,并在窗口调整大小小于特定宽度时重建轮播。
I would also like to thank Ken Wheelerfor the Tweets and advice!
我还要感谢Ken Wheeler的推文和建议!
JS
JS
$(document).ready(function () {
touchsliderone();
onresize();
$(window).resize(function () {
onresize();
});
});
// Resize
function onresize () {
touchslidertwo();
touchsliderthree();
touchsliderfour();
}
// Header Carousel
function touchsliderone() {
$('.touchslider_one').slick({
autoplay: true,
infinite: true,
speed: 1500,
autoplaySpeed: 3000,
dots: false,
slidesToShow: 1,
slidesToScroll: 1,
fade: true,
cssEase: 'linear',
});
}
// Boxes Carousel
function touchsliderfour() {
var $touchsliderfour = $('.touchslider_four');
if ($(window).width() < 376) {
if($touchsliderfour.hasClass('slick-initialized')) {
$touchsliderfour.unslick();
}
$touchsliderfour.slick({
autoplay: false,
infinite: true,
speed: 1500,
adaptiveHeight: true,
dots: false,
slidesToShow: 1,
slidesToScroll: 1,
cssEase: 'linear'
});
} else {
if($touchsliderfour.hasClass('slick-initialized')) {
$touchsliderfour.unslick();
}
}
}
// Featured Products Carousel
function touchsliderthree() {
var $touchsliderthree = $('.touchslider_three');
if ($(window).width() < 376) {
if($touchsliderthree.hasClass('slick-initialized')) {
$touchsliderthree.unslick();
}
$touchsliderthree.slick({
autoplay: false,
infinite: true,
speed: 1500,
adaptiveHeight: true,
dots: false,
slidesToShow: 1,
slidesToScroll: 1,
cssEase: 'linear'
});
} else {
if($touchsliderthree.hasClass('slick-initialized')) {
$touchsliderthree.unslick();
}
}
}
// Logos Carousel
function touchslidertwo() {
var $touchslidertwo = $('.touchslider_two');
if ($(window).width() < 376) {
if($touchslidertwo.hasClass('slick-initialized')) {
$touchslidertwo.unslick();
}
$touchslidertwo.slick({
autoplay: true,
infinite: true,
speed: 1500,
autoplaySpeed: 6000,
dots: false,
slidesToShow: 1,
slidesToScroll: 1,
cssEase: 'linear'
});
} else {
if($touchslidertwo.hasClass('slick-initialized')) {
$touchslidertwo.unslick();
}
$touchslidertwo.slick({
autoplay: true,
infinite: true,
speed: 1500,
autoplaySpeed: 6000,
dots: false,
slidesToShow: 5,
slidesToScroll: 5,
cssEase: 'linear'
});
}
}