Skip to content

Instantly share code, notes, and snippets.

@xlawok
Created September 16, 2021 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlawok/b1d72ead578f1fa7a46057721b0e33bd to your computer and use it in GitHub Desktop.
Save xlawok/b1d72ead578f1fa7a46057721b0e33bd to your computer and use it in GitHub Desktop.
jQuery plain slider - img only sliding - header is still
var arrow_wrapper=$('.arrow-wrapper');
if($(arrow_wrapper)){
var prev=$('.arrow-wrapper .prev');
var next=$('.arrow-wrapper .next');
var banner_imgs = $('.banner-img-wrapper .banner-img-cnt');
var banner_img_length = $(banner_imgs).length;
console.log(banner_img_length);
$(next).click(function(e) {
e.preventDefault();
let active_img=$('.banner-img-wrapper .banner-img-cnt.active').index();
console.log(active_img);
if(active_img==banner_img_length-1){
$(banner_imgs[active_img]).removeClass('active');
$(banner_imgs[0]).addClass('active');
}
else{
$(banner_imgs[active_img]).removeClass('active');
$(banner_imgs[active_img+1]).addClass('active');
}
});
$(prev).click(function(e) {
e.preventDefault();
let active_img=$('.banner-img-wrapper .banner-img-cnt.active').index();
console.log(active_img);
if(active_img==0){
$(banner_imgs[active_img]).removeClass('active');
$(banner_imgs[1]).addClass('active');
}
else{
$(banner_imgs[active_img]).removeClass('active');
$(banner_imgs[active_img-1]).addClass('active');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment