Slide a div from right to left using animate()

前端 未结 1 998
鱼传尺愫
鱼传尺愫 2020-12-15 10:34

I want a div \'.whole\' to animate (slide from right to left)

jQuery

$(\'#menu\').click(function() {
      $(\'.whole\').toggleClass(\'r         


        
相关标签:
1条回答
  • 2020-12-15 11:17

    This should work:

    $('#menu').click(function(event) {
          event.preventDefault(); // because it is an anchor element
          $('.whole').animate({
              right: '200px'
          });
          $('#slideMenu').toggle();
    });
    

    But your position property should already be set in CSS or you might not get exactly what you need.

    Working JSFiddle

    To explain: the function takes a JS object of properties, like this:

    {
        right: '200px',
        somethingElse: 'value',
        myboolean: true
    }
    

    you can also assign this to a var and pass it to animate:

    var cssProperties = { right: '200px' }
    
    $('#menu').click(function() {
      $('.whole').animate(cssProperties);
    });
    

    You can pass other arguements as readable in the documentation.

    0 讨论(0)
提交回复
热议问题