Change amount of visible slides for tablet & mobile devices - slider

I'm using bxslider and I want to make only one slide appear when on tablet and mobile (768px and down), but when above 768px then I'd like 6+ slides to appear. Can anyone help me out with this please?
<script>
$(function(){
$('.bxslider').bxSlider({
captions: true,
speed: 900,
pause: 7000,
startSlide: 0,
infiniteLoop: true,
auto: true,
video: true,
touchEnabled: false,
pager: false,
});
});
if ( $(window).width() < 768) {
var myslider = $('.bxslider').bxSlider({
...
maxSlides : 1,
});
}
else {
var myslider = $('.bxslider').bxSlider({
...
maxSlides : 4,
});
}
</script>
If anyone could help that would be amazing.

You can try to remove the first bxSlider() instance, you call it only inside of the conditions:
<script>
$(document).ready(function(){
$(function(){
if( $(window).width() < 768) {
$('.bxslider').bxSlider({
captions: true,
speed: 900,
pause: 7000,
startSlide: 0,
infiniteLoop: true,
auto: true,
video: true,
touchEnabled: false,
pager: false,
maxSlides: 1
});
} else {
$('.bxslider').bxSlider({
captions: true,
speed: 900,
pause: 7000,
startSlide: 0,
infiniteLoop: true,
auto: true,
video: true,
touchEnabled: false,
pager: false,
maxSlides: 4
});
}
});
});
</script>

Related

Swiper: virtual and loop not working together

codeLink: https://codepen.io/wuyangqin/pen/OJEeQBg
var swiper = new Swiper(".swiper-container", {
height: 400,
width: 240,
loop: true,
autoplay:{
delay: 2000
},
direction: 'vertical',
slidesPerView: 1,
centeredSlides: false,
spaceBetween: 30,
freeMode: true,
freeModeSticky: true,
mousewheel: true,
slideToClickedSlide: true,
pagination: {
el: ".swiper-pagination",
type: "fraction"
},
scrollbar: {
el: ".swiper-scrollbar",
draggable: true,
dragSize: 40,
},
virtual: {
slides: (function() {
var slides = [];
for (var i = 0; i < 4; i += 1) {
slides.push(
'<img src="https://picsum.photos/600/600/?image=' +
(i + 1) +
'"/><p>' +
(i + 1) +
"</p>"
);
}
return slides;
})()
}
});
When I set Loop:true, Swiper will stop when it reachEnd;
I tried the issue https://github.com/nolimits4web/swiper/issues/3070 But still not working
Expect loop and virtual working together

Toastr Spinner animation

How to make progress-bar reverse animation left to right?
$(document).ready(function() {
toastr.options = {
'closeButton': true,
'debug': false,
'newestOnTop': false,
'progressBar': false,
'positionClass': 'toast-top-left',
'preventDuplicates': false,
'showDuration': '1000',
'hideDuration': '1000',
'timeOut': '5000',
'extendedTimeOut': '1000',
'showEasing': 'swing',
'hideEasing': 'linear',
'showMethod': 'fadeIn',
'hideMethod': 'fadeOut',
}
});
Override the css class (toast-progress)
.toast-progress {right: 0; left: auto;}

Setting the correct height in vertical mode in Swiper

It's been days that I'm working on setting the swiper in my application but I still no luck and found no working sample anywhere from here to the Github issues or elsewhere on the net.
I can not set a dynamic height for the swiper in vertical mode via none of the suggested solutions to this problem.
I have several images as slides that give a height of thousands of pixels but if I switch it to a text it is fine as the height of the text is like 10 px. Any div above a certain height will result in abnormal height.
I found that the suggested CSS does not work as it just limits the height of the window and is very unpleasant as the pictures are cut off.
The js solutions are the correct way to do it but I can not find a working solution and the ones that I have tried all result in half of the job solutions.
It seems the correct way uses the onSlideChangeStart to correct the next slide height like below but this does not work as the swiper of the vertical is not recognized in its own settings.
onSlideChangeStart: (swiper)->
$(swiper.slides).each ->
$(this).css height: if $(this).index() != swiper.activeIndex then 0 else 'auto'
I tried to use the active class instead of the API as it is not working when calling even the swiperV.activeIndex in its own onSlideChangeStart like below but swiper-slide-active is not defined.
This is my settings for the 3 nested sliders.
var swiperVV = new Swiper('.swiper-container-vv', {
direction: 'vertical',
updateOnWindowResize: true,
grabCursor: true,
loop: true,
mousewheel: true,
lazy: true,
zoom: true,
effect: 'slide',
spaceBetween: 0,
pagination: {
el: '.swiper-pagination-v',
clickable: true,
},
});
var swiperH = new Swiper('.swiper-container-h', {
initialSlide:0,
spaceBetween: 0,
autoHeight: true,
updateOnWindowResize: true,
grabCursor: true,
loop: true,
parallax: true,
lazy: true,
effect: 'slide',
pagination: {
el: '.swiper-pagination-h',
clickable: true,
},
scrollbar: {
el: '.swiper-scrollbar',
hide: true,
},
});
var swiperV = new Swiper('.swiper-container-v', {
direction: 'vertical',
autoplay: {
delay: 5000,
},
autoHeight: true,
updateOnWindowResize: true,
grabCursor: true,
loop: true,
mousewheel: true,
lazy: true,
zoom: true,
effect: 'slide',
spaceBetween: 0,
pagination: {
el: '.swiper-pagination-v',
clickable: true,
},
slideChange: resizeSwiper()
});
function resizeSwiper() {
console.log($('.swiper-container-v .swiper-slide swiper-slide-active').height());
$('.swiper-container-v, .swiper-container-v .swiper-slide').css({ height: $('.swiper-container-v .swiper-slide .swiper-slide-active').height() });
}
i have gone through all the samples of suggested users like the ones listed below in github, stackoverflow and codepen.
https://github.com/nolimits4web/swiper/issues/48
https://github.com/nolimits4web/Swiper/issues/153
This is the workaround worked for me
if (typeof Swiper != "undefined"){
var popularSwiper = new Swiper(".popularSwiper", {
direction: "vertical",
autoHeight: true,
autoplay: {
delay: 5000,
},
pagination: {
el: ".swiper-pagination",
clickable: true,
},
on:{
init:function(){
setSlideHeight(this);
},
slideChangeTransitionEnd:function(){
setSlideHeight(this);
}
}
});
function setSlideHeight(that){
$('.swiper-slide').css({height:'auto'});
var currentSlide = that.activeIndex;
var newHeight = $(that.slides[currentSlide]).height();
$('.swiper-wrapper,.swiper-slide').css({ height : newHeight })
that.update();
}
}
It's working for me.
calculate the total height of the swiper container including gap between slides.
then set the swiper container height to the previously calculated height
let pdpThumb = new Swiper('#pdp-thumbCarousel', {
slidesPerView: 4,
direction: 'vertical',
spaceBetween: 10,
freeMode: true,
loop: true,
on: {
init: (swiper) => {
let totalGap = swiper.passedParams.spaceBetween * (swiper.passedParams.slidesPerView - 1);
let containerHeight = swiper.passedParams.slidesPerView * swiper.slides[0].clientHeight + totalGap;
swiper.el.style.height = containerHeight + 'px';
},
},
});

How to fix Slick Slider (Slick.JS) if it breaks on click event within the div?

I added Slick slider for any device under 1024px, however every time a button within the div is clicked and the page is refreshed, the slider is gone and it leaves a mess. It fixes itself if I change the device width from the console. I tried adding a function to reinitialize it every time a button is clicked, but for some reason 'reInit' does not work. I can't provide Jsfiddle, if someone could help based on my description, I would appreciate it.
function slickify(){
event.preventDefault();
$('.cart-list').not('.slick-initialized').slick({
infinite: false,
responsive: [
{
breakpoint: 1024,
autoplay: false,
dots: true,
infinite: false,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
dots: true
}
},
{
breakpoint: 786,
autoplay: false,
dots: true,
infinite: false,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
dots: true
}
},
{
breakpoint: 550,
autoplay: false,
dots: true,
infinite: false,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
dots: true
}
}
]
});
}
$(window).resize(function(){
event.preventDefault();
var $windowWidth = $(window).width();
if ($windowWidth < 1024) {
slickify();
$(window).resize(function() {
$('.cart-list').slick('resize');
event.preventDefault();
});
$(window).on('orientationchange', function() {
$('.cart-list').slick('resize');
event.preventDefault();
});
}
});
$('.cart-list').on('click', function() {
$('.cart-list').slick('reInit');
});
});
I've tried adding a simple function such as :
('body').on('click', function() {
('.slick-slider-div').slick('reInit');
});
where reInit is reinitialization as per Slick.JS documentation. However, it breaks any click event on the page. I also tried to make the click event only withing the div, still no result. The '.slick-initialized' class just disappears on click event.

Autoplay in slick slider stop working after on Next or Previous arrows click

I have slick slider on my page. After click on Next or Previous arrows in slick slider autoplay stop working. But when I click on any place on the page it starts to autoplay again. How I can fix this? I need to have autoplay even after arrow click.
JS:
jQuery(document).ready(function ($) {
var $slider = $('.slider');
if ($slider.length) {
$slider.slick({
slidesToShow: 7,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 1500,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true,
autoplay: true,
autoplaySpeed: 1500
}
},
{
breakpoint: 600,
settings: {
autoplay: true,
autoplaySpeed: 1500,
slidesToShow: 2,
slidesToScroll: 2
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
autoplay: true,
autoplaySpeed: 1500
}
}
]
});
}
});
To fix this need to add:
pauseOnFocus: false,
pauseOnHover: false