jquery - 调整窗口大小时 move 图像或向上划分?

标签 jquery css resize window move

我的 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/

相关文章:

jquery - 将 JScrollpane 添加到我的 tbody 时遇到问题

Javascript:按下 'back'按钮时如何取消禁用按钮

javascript - 将 CSS 与 React/JSX 结合使用

html - 内联 block 50% 元素的大小调整不均匀

qt - 将 QLineEdit 的宽度调整为内容(并且比预期的要短)

jquery - 如何在上次执行后触发点击事件

javascript - 隐藏元素并根据下拉选择不需要它们

html - 如何在悬停时隐藏导航中的分隔线?

html - IE8 忽略 margin-top 知道为什么吗?

图像调整大小在 Bootstrap 框架的 IE8 中不起作用