0

我的 html 中有一个带有“拉伸”类的图像。

目前,使用 css,此图像会随着窗口大小重新调整为屏幕宽度的 100%。我还希望它在调整窗口大小时向上移动。

我假设这可以用 jQuery 完成,但我不太确定。基本上,“顶部”css 值只需要随着屏幕宽度的变化而变化。

这是当前正在重新调整大小的 css:

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

谢谢,

韦德

4

2 回答 2

3
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;
});
于 2010-05-23T04:20:44.347 回答
0

使用相对 top值(百分比等)。

于 2010-05-23T02:33:22.870 回答