jquery animate for element attributes not style

前端 未结 5 500
心在旅途
心在旅途 2021-01-11 18:40

ASAIK jquery animate function accepts style properties only. but i want to animate the attributes of an element. consider a SVG element rectangle

         


        
5条回答
  •  生来不讨喜
    2021-01-11 18:54

    I would try something like this

    
        
    
    

    in the script :

    var myElemX = $('.myElement').attr('x');
    var myElemY = $('.myElement').attr('y');
    $("#rect1").animate({
        left: myElemX+'px',
        top:  myElemY+'px'
    }, 1500 );
    

提交回复
热议问题