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

前端 未结 5 1337
执笔经年
执笔经年 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 06:52

    Maybe

    var button_init_marginLeft;
    $(document).ready(function () {
       button_init_marginLeft = $('#Button1').css("marginLeft");
       example_animate(10, true);
       example_animate(null, false);
    });
    
    function example_animate(px, to_left) {
      if (to_left)
      {
        $('#Button1').animate({
          'marginLeft': px
        });
      }
      else
      {
        $('#Button1').animate({
          'marginLeft': button_init_marginLeft
        });
      }
    }
    

    ?

提交回复
热议问题