开发者

Move Image or Div Up As Window Resizes?

I have an image in my html with a class of "stretch".

Currently, with css, this image re-sizes as the window re-sizes to be 100% of the screen width. I would also like it to move upwa开发者_运维问答rds as the window is being re-sized.

I'm assuming this can be done with jQuery but I am not quite sure. Basically the "top" css value just needs to change as the screen width does.

Here is the css that is currently re-sizing it:

.stretch {
width: 100%;
height: auto;
min-height: 420px;
position: absolute;
top: -200px;
}

Thanks,

Wade


var origWidth;
$(document).ready(function() {
    origWidth = $(window).width();  //store the window's width when the document loads
});

$(window).resize(function() {
    var curWidth = $(window).width(); //store the window's current width
    var delta = (curWidth- origWidth);
    $(".stretch").offset({top:($(".stretch").offset().top + delta)});
    origWidth = curWidth;
});


Use a relative top value (percent, etc.).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜