[英]Image slider jquery not working
$("#forward_carousel").click( () => { //sets timeout back and starts clearTimeout(timeout); timeout = 0; var i; var x = $(".carousel_size");//class for the pictures in carousel for (i = 0; i < x.length; i++) { x[i].style.display = "none"; } slideIndex++; if (slideIndex > x.length) {slideIndex = 1} x[slideIndex-1].style.display = "block"; timeout =setInterval(carousel, 5000); }) $("#backward_carousel").click( () => { clearTimeout(timeout); timeout = 0; var i; var x = $(".carousel_size");//class for the pictures in carousel for (i = 0; i < x.length; i++) { x[i].style.display = "none"; } slideIndex--; if (slideIndex < x.length){slideIndex = 3} x[slideIndex-1].style.display = "block"; timeout =setInterval(carousel, 5000); })
Your condition for backward index is not correct. 您的向后索引条件不正确。
Change this line: 更改此行:
if (slideIndex < x.length){slideIndex = 3}
To this: 对此:
if (slideIndex < 0){slideIndex = x.length}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.