Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  133] [ 6]  / answers: 1 / hits: 179482  / 13 Years ago, mon, august 22, 2011, 12:00:00

I want to reposition an entire div and its contents up about 10-15 pixels.



How can I do this?



Note: this is slider element, so when I click a button the slider slides down. Once it is finished I want to reposition it up about 15 pixels.


More From » jquery

 Answers
18
$('#div_id').css({marginTop: '-=15px'});


This will alter the css for the element with the id div_id



To get the effect you want I recommend adding the code above to a callback function in your animation (that way the div will be moved up after the animation is complete):



$('#div_id').animate({...}, function () {
$('#div_id').css({marginTop: '-=15px'});
});


And of course you could animate the change in margin like so:



$('#div_id').animate({marginTop: '-=15px'});


Here are the docs for .css() in jQuery: http://api.jquery.com/css/



And here are the docs for .animate() in jQuery: http://api.jquery.com/animate/


[#90486] Saturday, August 20, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aubreeg

Total Points: 437
Total Questions: 102
Total Answers: 102

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;