我的 html 中有一张带有“拉伸(stretch)”类的图像。
目前,使用 css,此图像会随着窗口大小调整为屏幕宽度的 100% 而调整大小。我还希望它在调整窗口大小时向上 move 。
我假设这可以用 jQuery 完成,但我不太确定。基本上,“顶部”css 值只需要随着屏幕宽度的变化而变化。
这是当前正在调整其大小的 css:
.stretch {
width: 100%;
height: auto;
min-height: 420px;
position: absolute;
top: -200px;
}
谢谢,
韦德
最佳答案
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;
});
关于jquery - 调整窗口大小时 move 图像或向上划分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2890396/