【问题标题】:jquery animeted on multi thread多线程上的jquery动画
【发布时间】:2013-02-07 12:00:15
【问题描述】:

jquery 动画函数在多线程上工作吗?

在我的代码中......假设我点击顶部按钮并调用函数工作正常......

现在单击任何剩余的一次....第二个功能也可以使用,但也可以使用第一个调用。

那么,我如何一次调用一个函数?

它是多线程,然后它是杀死它的方法吗?

<table width="1200px" height="600px" align="center">
        <tr>
            <td>
            </td>
            <td style="text-align: center">
                <button id="btntop">
                    top</button>
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
                <button id="btnleft">
                    left</button>
            </td>
            <td style="text-align: center">

                <img id="book" src="Image/images.jpg" alt="" width="250" height="123" style="position: relative;
                    left: 10px;" />

            </td>
            <td>
                <button id="btnright">
                    right</button>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td style="text-align: center">
                <button id="btnbottom">
                    bottom</button>
            </td>
            <td>
            </td>
        </tr>
    </table>
    <script type="text/javascript">


        function anim(direction) {


            if (direction == "top") {

                $('#book').animate({

                    top: '-=10'

                }, 200, function () {


                        anim("top");

                });

            }

            if (direction == "left") {
                $('#book').animate({

                    left: '-=10'
                }, 200, function () {

                        anim("left");

                });
            }

            if (direction == "right") {
                $('#book').animate({

                    left: '+=10'
                }, 200, function () {

                        anim("right");

                });
            }

            if (direction == "bottom") {
                $('#book').animate({

                    top: '+=10'
                }, 200, function () {

                        anim("bottom");

                });
            }
        }


        $('#btntop').hover(function () {

            anim("top");

        });


        $('#btnleft').hover(function () {

            anim("left");

        });

        $('#btnright').hover(function () {


            anim("right");

        });

        $('#btnbottom').hover(function () {


            anim("bottom");

        });


    </script>

【问题讨论】:

    标签: jquery


    【解决方案1】:

    您在hover() 上调用您的anim() 函数,这不是一个好主意。改为click()

    至于第二部分,在每个 4 按钮单击处理程序中调用 anim() 之前添加 $('#book').stop(true);

    $('#btntop').click(function () {
        $('#book').stop(true);
        anim("top");
    });
    
    $('#btnleft').click(function () {
        $('#book').stop(true);
        anim("left");
    });
    
    $('#btnright').click(function () {
        $('#book').stop(true);
        anim("right");
    });
    
    $('#btnbottom').click(function () {
        $('#book').stop(true);
        anim("bottom");
    });
    

    它将停止所有当前正在运行的动画并开始新的动画。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多