代码很短,这里是:
http://jsfiddle.net/L4Ry3/170/
$(document).ready(function(){
$('#previous_frame').on("click",function(){
var $last = $('.frames li:last-child')
$('.frames').prepend($last)
$last.css({left:'-33%'})
$last.animate({left:'0%'})
});
$('#next_frame').on("click",function(){
var $first = $('.frames li:first-child');
$('.frames').append($first);
$('.frames li:first-child').css({right:'-33%'});
$('li:first-child').animate({right:'0%'})
});
})
如果单击左键,则会慢慢移动图像。当我单击右侧时,图像立即切换到位置。我不明白为什么会这样。
答案 0 :(得分:2)
这是因为您添加了left
规则。它保持为0.您可以注意到它首先工作,然后停止为您单击的图像停止工作,但继续为其余图像工作。
在next_frame
功能添加
$('.frames li:first-child').css({left:''});
删除left
。
您可以在this fiddle中看到它。
通过单击向左全部执行测试,然后再次单击右键。
显然,left
样式规则比right
更具优势。如果你同时只考虑left
,那么虽然right
是动画,但它仍然保持0%左右。删除left
规则允许css引擎查看right
并显示所需的动画。
答案 1 :(得分:0)
将下一帧点击事件中的right
更改为left
,将-
更改为+
..这应该可以解决问题
试试这个
$(document).ready(function(){
$('#previous_frame').on("click",function(){
var $last = $('.frames li:last-child')
$('.frames').prepend($last)
$last.css({left:'-33%'})
$last.animate({left:'0%'})
});
$('#next_frame').on("click",function(){
var $first = $('.frames li:first-child');
$('.frames').append($first);
$('.frames li:first-child').css({left:'33%'}); //<----here
$('li:first-child').animate({left:'0%'})//<----here
});
})