jquery - 立即引发完全火灾

标签 jquery

在下面的代码中,我希望 diag1 div 缓慢递增 - 每个动画结束后一次。相反,它立即变为 20,并且动画滞后。我认为 .animate 中函数参数的全部要点是在动画完成后回调函数。有人能发现我的问题吗?

<!DOCTYPE html>
<html>
    <head>
        <title>TST</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <link rel="stylesheet" href="http://api.jquery.com/jquery-wp-content/themes/jquery/css/base.css?v=1">
        <script>
            PLAY=true;
            END_TIME = 20;
            CURRENT_TIME = 1;

            function scrollManager() {
                if(PLAY==true && CURRENT_TIME < END_TIME) {
                    CURRENT_TIME++;
                    scrollLeft();
                }
            }

            function scrollLeft() {
                $('#diag1').html(CURRENT_TIME);
                $('#s6').animate(
                    {'padding-left': '-=5%'},
                    1000, 'linear', scrollManager());
            }

            $(function() {
                $('#play_button').click(function() {
                    PLAY = true;
                    scrollManager();
                });
            });
        </script>
    </head>

    <body>
        <div class="app">
            <div id="ui">
                <button id="play_button">Play</button>
                <div class="row">
                    <div class="tst1">
                        <div id="s6" style="padding-left:70%;width:5%;background-color:red;">
                            <div>TEST</div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="diag1">Diagnostic 1: </div>
        </div>
    </body>
</html>

最佳答案

删除scrollManager上的()()是JS中调用函数的运算符。

$('#s6').animate({'padding-left': '-=5%'}, 1000, 'linear', scrollManager);

关于jquery - 立即引发完全火灾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27726909/

相关文章:

javascript - 使用异步 ajax 或 jquery 完全重新加载页面

jquery - 在 JQuery datetimepicker 中设置日期和时间

javascript - 垂直滚动图片库

javascript - 获取 "RangeError: Maximum call stack size exceeded"错误

JavaScript 全部开/关按钮

php - 无法在 Laravel 的 app.scss 中导入 "bootstrap-select"

javascript - 如何使用 jQuery 将类添加到基于子类的父元素

php - 使用 Jquery、PHP、Mysql 进行 Ajax 分页

jquery - fullcalendar,在工具栏后插入复选框

jquery - 动画从顶部向下滑动