开发者

Jquery animating position moving when click on it [closed]

开发者 https://www.devze.com 2023-03-02 16:17 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not开发者_运维知识库
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not开发者_运维知识库 generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I have some a tag with position:absolute, and when I click on it, I want to move this tag 100px left (animated).

How to do this?


This will move your element (having an ID of #my_link) 100 pixels to the left when clicked.

$('#my_link').on('click', function () {
    $(this).animate({
        left: '-=100'
    });
});
  • jQuery .animate()
  • jQuery .click()


Have you taken a look at jQuery's animate? You can animate CSS properties such as left.

$('#myDiv').click(function(){
    $(this).animate({'left' : '-=100'});
});


this should do it

jsfiddle example here http://jsfiddle.net/EtfCV/

$('#yourdiv').click(function() {
      $(this).animate({
        left: '-=100'
      }, 5000, function() {
        // Animation complete.
      });
    });


Check out the example, and the animate method at the jQuery site. It's really basic stuff.

$('#tralala').click(function(evt) {
    evt.preventDefault();
    $(this).animate({
        left : '-=100'
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消