javascript - 修复了 jQuery 换行

标签 javascript jquery html css

在我的页面中,我有一个 div(固定环绕),我想在滚动后移动它。 我用 jQuery 尝试了一些东西,但是 div 的高度太高,超过了页脚。

img1

img2

这是我的代码:

对不起,edit2:

var elementPosition = $('#fixed-wrapper').offset();
$(window).scroll(function() {
  if ($(window).scrollTop() > elementPosition.top) {
    $('#fixed-wrapper').css('position', 'fixed').css('top', '0').css('margin', '20px 1%');
  } else {
    $('#fixed-wrapper').css('position', 'static');
  }
});
#header {
	width: 101%;
	padding: 10px 0px 0px;
	margin: -10px -10px 10px -10px;
	background-color: rgba(0, 0, 0, 0.7);
	display: table;
	min-width: 700px;
}

#main-bets{
	display: table;
	float: left;
	width: 68%;
	margin-left: 7%;
	margin-top: 20px;
	margin-bottom: 30px;
	min-width: 900px;
	max-width: 900px;
	background-color: rgba(0, 0, 0, 0.5);
}

#fixed-wrapper {
    	display: table;
    	float: right;
    	width: 22%;
    	right: 5px;
    	margin: 20px 1%;
    	max-width: 300px;
}

#footer {
	width: 101%;
	padding: 10px 0px 0px;
	margin: 20px -10px -10px -10px;
	background-color: rgba(0, 0, 0, 0.7);
	display: table;
	clear: both;
}
<div id="header">
    ...
</div>

<div id="main-bets
    ...
</div>

<div id="fixed-wrapper">
	....
</div>

<div id="footer">
	...
</div>

最佳答案

您可以使用我的 sticky float jQuery 插件(demo page),或使用相对较新的 CSS 属性:position:sticky (在旧的 Egde/IE 中不是 supported)

关于javascript - 修复了 jQuery 换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44481978/

相关文章:

javascript - 正则表达式中的未终止组

javascript - CKEditor 工具栏定位到带有 float 图像的内容的右侧

html - 为什么我的完整表格是粗体的?

jquery - 如何将悬停按钮添加到链接

javascript - 在采取行动的情况下获取单选按钮的选定值

javascript - 在包含 javascript 的网站上使用 NodeJS 进行抓取

Javascript:将变量传递给 ShopifyApp 初始化

javascript - 编辑 woocommerce Assets 的正确方法是什么?

javascript - 更改多个 iframe 的内容

javascript - 从每个 div 的 data-src 获取数据并在 div 上使用该数据