【问题标题】:script will animate but not toggle脚本将动画但不切换
【发布时间】:2017-01-12 04:48:20
【问题描述】:

我正在运行一个应该上下切换的脚本

$(document).ready(function(){
$('#movedown').toggle(function() {
$(".menu2").animate({top: '-=1512px'}, 500);
}, function() {
$(".menu2").animate({top: '+=1512px'}, 500);
});
});

它不会切换http://toddheymandirector.com/index_mobile99.html,但如果我用点击替换切换,它会向下滑动http://toddheymandirector.com/index_mobile88.html 我哪里错了?

【问题讨论】:

    标签: javascript jquery toggle


    【解决方案1】:

    你使用jQuery.toggle错了,

    .toggle([持续时间] [,完成])

    说明:显示或隐藏匹配的元素。

    请参阅:jQuery.toggle

    toggle 用于显示/隐藏匹配的元素,而不是在您尝试使用它时在两个功能之间切换。


    据我了解,您想让一个元素上下“摆动”吗?

    这应该可行:

    $(".menu2").animate({top: '-=1512px'}, 500).animate({top: '+=1512px'}, 500)
    

    【讨论】:

    • 谢谢。那么 .animate 是否适合让元素在上下滑动之间交替?
    • @REELHERO 一起使用一行动画:$(".menu2").animate({top: '-=1512px'}, 500).animate({top: '+=1512px'}, 500) 并将它们推入 while 循环。
    • 谢谢。就像: $(document).ready(function(){ $(".menu2").animate({top: '-=1512px'}, 500).animate({top: '+=1512px'}, 500 ) }); });
    • 道歉:$(document).ready(function(){ $('#movedown').click(function() { $(".menu2").animate({top: '-=1512px'}, 500).animate({top: '+=1512px'}, 500) }); });
    • 我尝试了上面的脚本它向下滑动并再次单击它向上滑动几个像素然后向下滑动:toddheymandirector.com/index_mobile888.html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    相关资源
    最近更新 更多