-1
我是一個初學jQuery,我試圖使滑塊響應和工作,但我有一些錯誤,我想解決,首先當傳遞到下一張圖片有時它只是變成白色,它不再工作,其次有些時候它開始變得越來越快。jquery滑塊響應問題
有什麼建議嗎?
.mascara
{ width: 100%; height: 100%;
overflow: hidden;
}
.carrusel{ position: relative; width: 100%; height: 100%; }
.carrusel li{ width:25%; height: 100%; float: left; background-repeat: no-repeat; background-position: center; background-size: cover; }
<script src="jquery-2.0.3.min.js"></script>
<script>
var cantidadFotos = $('.carrusel li').size();
var incremento = $('.mascara').width();
var limite = (cantidadFotos-1) * incremento;
var velocidad = 550;
$('.carrusel').css('width', (cantidadFotos*100)+"%");
$('.carrusel li').css('width', incremento+"px");
var posX = 0;
resize();
function resize()
{
$(window).resize(function() {
incremento = $('.mascara').width();
$('.carrusel li').css('width', incremento+"px");
posX = -(incremento * imagenes);
$('.carrusel').css('left', posX+"px");
});
setInterval(function(){ nextFoto(); }, 3000);}
var imagenes = 0;
function nextFoto(){
imagenes++;
posX+= -incremento;
if (posX<-limite){
posX=0;
imagenes = 0;
$('.carrusel').css({ left: posX });
}
$('.carrusel').animate({ left: posX},350);
// $('.carrusel').css({ left: posX});
return false;
}
</script>
嗨,你可以創建一個小提琴?也嘗試在你的帖子中編輯你的問題,而不是在評論中,所以我們可以很好地閱讀你的代碼。你可以讓小提琴http://jsfiddle.net/這裏 – bumbumpaw
http://jsfiddle.net/mgHn4/代碼在這裏!我需要幫助 – user3308331