Jquery animating position moving when click on it [closed]
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'
});
});
精彩评论