我制作了一个工作正常的旋转木马,但现在我想让我点击的元素移动到旋转木马的中间,即旋转木马应该移动直到我点击的元素在中间居中。
在这里查看我到目前为止的工作:http://jsfiddle.net/HkTks/6/
我正在使用 animate()
但不知道我是否应该使用 left
、marginLeft
或 scrollLeft
属性。我真的被困住了,因为我不知道该做什么逻辑,我什至不知道从哪里开始。请给我一些启示。
非常感谢
最佳答案
我之前做过类似的东西,比较挑剔,不过就是几笔而已。 不过没时间在您的代码中对其进行测试。
$('.iconsList li').click(function(){
// next two should be one line
var newLeftPos = 0 -(($(this).width() + $(this).css('margin-right')) * ($(this).index + 1)) + ($(this).parents('.iconsList').width() / 2);
$('.iconsList li').animate({'left', newLeftPos + 'px'},400);
})
关于javascript - 在 jquery/javascript 中单击时将元素移动到轮播的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10139677/