0
我用一個很簡單的JS爲我的滑塊,當前圖像水平滑動,向左或向右取決於所按的箭頭。我遇到的問題是,有上的動畫沒有延遲,所以如果你點擊方向箭頭迅速幾次,它需要一段時間的幻燈片追上並有很多奇怪的重疊。拖延滑塊動畫並將效果改爲淡入?
我想改變動畫效果,淡入淡出,併成立了一個延遲,這樣,直到當前幻燈片做動畫你不能前進到下一個或上一張幻燈片。任何幫助將不勝感激!
var slideInProgress = false;
var currentSlideIndex = 0,
slides;
function setTopSlider(){
if (jQuery('#top_slider #container .slide').length != 0) {
slides = jQuery('#top_slider #container > .slide');
for(var i=0; i <= slides.length; i++){
jQuery(slides[i]).css('left','100%');
};
jQuery(slides[currentSlideIndex]).css('left','0%');
var el=jQuery('.dot:eq('+currentSlideIndex+')');
src = el.css("background-image").replace("_off", "_over");
el.css("background-image", src);
el.addClass('active');
};
};
function slide(dir) {
var current, next, nextSlide;
current = jQuery(slides[currentSlideIndex]);
if(!isNaN(dir)){
next = dir;
if(next > currentSlideIndex)dir = 'left';
else dir = 'right';
};
if(dir == 'left'){
if(!next){
next = currentSlideIndex + 1;
if(next >= slides.length){
next = 0;
}
}
if (slideInProgress) {
return;
}
slideInProgress = true;
nextSlide = jQuery(slides[next]);
nextSlide.css('left','100%');
nextSlide.css('z-index',parseInt(current.css('z-index'), 10)+1);
nextSlide.animate({left: '0%'}, 1500);
current.animate({left: '-100%'}, 1500);
}else{
console.log('moving right');
if(!next){
next = currentSlideIndex - 1;
if(next < 0){
next = slides.length-1;
}
}
nextSlide = jQuery(slides[next]);
nextSlide.css('left','-100%');
nextSlide.css('z-index',parseInt(current.css('z-index'), 10)+1);
nextSlide.animate({left: '0%'}, 1500);
current.animate({left: '100%'}, 1500);
omplete: function(){
slideInProgress = false;
});
};
current.addClass('active');
nextSlide.removeClass('active');
var el=jQuery('.dot:eq('+currentSlideIndex+')');
src = el.css("background-image").replace("_over", "_off");
el.css("background-image", src);
el.removeClass('active');
el=jQuery('.dot:eq('+next+')');
src = el.css("background-image").replace("_off", "_over");
el.css("background-image", src);
el.addClass('active');
console.log('currentSlideIndex'+currentSlideIndex);
console.log('next'+next);
console.log('dir'+dir);
currentSlideIndex = next;
};
正好沒有工作是什麼?或者,你的更新代碼看起來如何? – betatester07
我對javascript的使用並不是很好,我確定我放錯了部分代碼。更新了我原來的帖子。再次感謝! – APAD1
經過測試和完美運作。你是天賜之物。謝謝!!!!! – APAD1