我的 html 中有一个带有“stretch”类的图像。
目前,使用 css,该图像的大小会随着窗口大小的调整而调整为屏幕宽度的 100%。我还希望它在调整窗口大小时向上移动。
我假设这可以用 jQuery 来完成,但我不太确定。基本上,“顶部”CSS 值只需要随着屏幕宽度的变化而变化。
这是当前正在调整其大小的 css:
.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;
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)