Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
36
rated 0 times [  43] [ 7]  / answers: 1 / hits: 18084  / 6 Years ago, fri, february 2, 2018, 12:00:00

I have a while loop that display posts using the slick slider multiple items format.



This displays and works with no problems.



I want to be able to 'disable' the slick slider functionality when the viewport is less than 481px and just list the posts.



I have a conditional javascript function (below) to target viewports less than 481px



jQuery(window).on('resize',function()
{
var viewportWidth = jQuery(window).width();

if (viewportWidth < 481)
{
}
else
{

}
});


I've added some jquery to remove the classes multiple-items, slick-slider and slick-initialized. The slides disappear. I would like to continue to display all the posts.



Can someone please point me in the right direction on how I can deactivate the slick slider functionality when viewing the site on viewports less than 481px?



Full code:



<div id=box class=multiple-items>
<?php
while($search_results_featured_users->have_posts()) : ?>
<div>
<a href=<?php the_permalink();?>>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
</a>
</div>
<?php
endwhile;
wp_reset_postdata(); ?>
</div>

<script>
jQuery(document).ready(function(){

// on screen resize
jQuery(window).on('resize',function()
{
var viewportWidth = jQuery(window).width();

if (viewportWidth < 481)
{
jQuery(#box).removeClass(multiple-items slick-initialized slick-slider);
}
else
{

}
});

jQuery('.multiple-items').slick({
infinite: true,
slidesToShow:6,
slidesToScroll: 2,
autoplay: true,
autoplaySpeed: 5000,
pauseOnHover: false,
dots: false,
arrows: true,
speed: 500,
cssEase: 'linear',
});

});
</script>


Any help much appreciated.


More From » jquery

 Answers
15

You can destroy Slick slider with unslick method



$(element).slick('unslick');


for example



jQuery(window).on('resize', function() {
var viewportWidth = jQuery(window).width();

if (viewportWidth < 481) {
$('.multiple-items').slick('unslick');
} else {
// Do some thing
}
});

[#55285] Tuesday, January 30, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janjadonb

Total Points: 4
Total Questions: 114
Total Answers: 118

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
janjadonb questions
;