我想使用jquery左右和左右移动按钮 [英] I want to move button left-right and right-left using jquery

查看:102
本文介绍了我想使用jquery左右和左右移动按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将按钮移动到左侧,但之后我又可以将它移动到右侧。
我也可以在这里使用延迟。

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.

这是我试过的代码:

  $(document).ready(function () {
      example_animate(10);


  });

  function example_animate(px) {

     $('#Button1').animate({
         'marginLeft': px

     });
 }


推荐答案

你可以使用它,它对我来说非常合作,它会不断地来回移动你的元素,你也可以改变动画的速度。

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);
            }
        });
    }
)};
}

使用此方法实现:

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

这篇关于我想使用jquery左右和左右移动按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆