I want to move button left-right and right-left using jquery

前端 未结 5 1336
执笔经年
执笔经年 2021-01-24 06:11

I am able to move button to left side but after that how i can again move it to right side. Can i also use delay here.

Here is the code that i have tried:



        
5条回答
  •  不思量自难忘°
    2021-01-24 07:03

    you can use this, it is working perfectly for me, it will continuously move your element back and forth, and you can also vary animation speed.

    function animatethis(targetElement, speed) {
            $(targetElement).animate({ marginLeft: "+=10px" },
    {
        duration: speed,
        complete: function () {
            targetElement.animate({ marginLeft: "-=10px" },
            {
                duration: speed,
                complete: function () {
                    animatethis(targetElement, speed);
                }
            });
        }
    )};
    }
    

    use this to implement:

    animatethis($('#controlid'), 1500);
    

提交回复
热议问题