开发者

How to move an entire div element up x pixels?

开发者 https://www.devze.com 2023-03-30 02:27 出处:网络
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

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 开发者_如何学Pythonabout 15 pixels.


$('#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/


$('div').css({
    position: 'relative',
    top: '-15px'
});


In css add this to the element:

margin-top: -15px; /*for exact positioning */
margin-top: -5%; /* for relative positioning */

you can use either one to position accordingly.


you can also do this

margin-top:-30px; 
min-height:40px;

this "help" to stop the div yanking everything up a bit.

0

精彩评论

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