如何修复一个jquery .animate边距滑块
How to fix a jquery .animate margin slider?
我的网址:http://www.grozav.com
我需要帮助修复缩略图滑块部分(投资组合)的代码。如果有人快速点击箭头两次,它就会偏离轨道,编码就会停止工作。
HTML标记:
<div id="portfolio">
<div id="up-arrow"><a href="#portfolio" title="Slide Up">UP</a></div>
<div id="thumbnails">
<div id="slider">
thumbnails go here
</div>
</div>
<div id="down-arrow"><a href="#portfolio" title="Slide Down">DOWN</a></div>
</div>
Jquery: $('#up-arrow a').stop().click(function(){
if($('#slider').css("margin-top")!='0px' ){
$('#slider').stop().animate({'margin-top':'+=360px'})
$('#down-arrow').css({'background-position':'0 0px'})
$('#down-arrow a').css({'cursor':'pointer'})
//CHANGE <='PX' VALUE FOR NEXT SLIDE
if($('#slider').css("margin-top")<='-360px'){
$('#up-arrow').css({'background-position':'0 -28px'})
$('#up-arrow a').css({'cursor':'help'}) }
$('#down-arrow').css({'background-position':'0 0px'})
}
else if ($('#slider').css("margin-top")>'0px') {
$('#slider').css({'margin-top':'0px'});
}
});
$('#down-arrow a').stop().click(function(){
if($('#slider').css("margin-top")!='-720px' || $('#slider').css("margin-top")<'-720px'){
$('#slider').stop().animate({'margin-top':'-=360px'})
$('#up-arrow').css({'background-position':'0 0px'})
$('#up-arrow a').css({'cursor':'pointer'})
//CHANGE <='PX' VALUE FOR NEXT SLIDE
if($('#slider').css("margin-top")<='-360px'){
$('#down-arrow').css({'background-position':'0 -27px'})
$('#down-arrow a').css({'cursor':'help'}) }
$('#up-arrow').css({'background-position':'0 0px'})
}
else if ($('#slider').css("margin-top")<'-720px') {
$('#slider').css({'margin-top':'-360px'});
}
});
当按钮位于幻灯片的开始和结束时,它会改变按钮的外观。由于缺乏滑块领域的知识,我这样编码。
我如何修复它,或者至少防止它点击两次?
为什么不将函数包装在if条件中,以检查滑动条是否正在动画?然后,它们将只在动画不发生时工作。
比如if( !$('#slider').is(':animated') ){ ... your code ... }
相关文章:
- 可以'使用jQuery animate时无法看到动画
- 如何使用jquery animate来回移动多个元素
- jQuery animate()函数没有't设置动画
- JQuery.animate();不以固定高度工作
- 有没有什么方法可以停止Jquery中的animate(也可以停止完整的回调函数)
- 有没有一种方法可以用步骤递归调用jQuery animate()
- jquery animate无法正常工作
- JQuery.animate()菜单幻灯片返回
- jQuery animate只在单击时工作一次
- 如何在不使用css转换的情况下将jQuery animate与css3属性相结合
- Implementation of jQuery 'animate' with Meteor
- jQuery:在 animate 属性上使用变量
- jQuery Animate 在创建图库滑块时不起作用
- jQuery的slideUp,slideDown,animate函数的任何替代品
- jQuery animate 会中断空格键滚动
- Jquery Animate on IE makes error
- 使用 jQuery animate 时绘制一个又一个对象的线条
- ToggleClass animate jQuery?
- $.animate() jQuery显示:表不影响未指定的空间尺寸
- 使用animate() JQUERY获取进度