gpt4 book ai didi

javascript - 在调整大小时保持 div 的位置与溢出相同?

转载 作者:行者123 更新时间:2023-11-28 03:35:31 25 4
gpt4 key购买 nike

我目前正在尝试调整我一直在研究的图像 slider 。我想要做的是在用户调整浏览器大小时保持 slider 与浏览器左侧相交的相同位置。检查下面的例子

            +------------------------+
| body |
+--------------------------------------------------+
| | |
| |<- Keep this aligned at the same |
| | position on browser resize? |
| | |
| | |
| | |
+--------------------------------------------------+
| |
+------------------------+


HTML:
<div id="scrollerWrapper">
<div id="imageScroller">
<img class="i" href="..." />
<img class="i" href="..." />
<img class="i" href="..." />
<img class="i" href="..." />
</div>
</div>

browserHeight = parseInt($(window).height(), 10);

galleryMargin = browserHeight * 0.025;
imageHeight = browserHeight - 80 - (galleryMargin * 2);
if (imageHeight < 250) {
imageHeight = 250;
}
$(".i").css("height", imageHeight + "px");

最佳答案

也许您可以更详细地了解您的问题,我从您的解释中理解的内容看起来像这样并且不需要任何 javascript

fiddle 在这里 http://jsfiddle.net/caramba/LzwUP/

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
* { padding:0px; margin:0px; }
</style>
</head>
<body>
<div style="position:absolute;width:100%;height:400px;background-color:orange;">
<div style="position:relative;left:0px;top:100px;width:500px;height:200px;background-color:navy;"></div>
</div>
</body>
</html>

关于javascript - 在调整大小时保持 div 的位置与溢出相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14643719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com