向下滚动页面后更改元素css位置 [英] changing an elements css position after scrolling down the page
本文介绍了向下滚动页面后更改元素css位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在弄乱一些试图抓住它的jquery。
I am messing around with some jquery trying to get to grips with it.
我有一个ul导航器,它有一个绝对位置设置但滚动页面后减去200像素我希望切换到固定的位置,以便导航始终保持在页面上。
I have a ul nav which has a absolute position set but after I scroll the page down by 200 pixels i would like that to switch to position fixed so that the nav always stays on the page.
我该怎么做?
下面是我正在处理的例子
below is the example I am working on
推荐答案
感谢大家这么快帮助
这就是我想要的
$(document).ready(function() {
var theLoc = $('ul').position().top;
$(window).scroll(function() {
if(theLoc >= $(window).scrollTop()) {
if($('ul').hasClass('fixed')) {
$('ul').removeClass('fixed');
}
} else {
if(!$('ul').hasClass('fixed')) {
$('ul').addClass('fixed');
}
}
});
});
我来自
< a href =http://satbulsara.com/tests/\"rel =noreferrer> http://satbulsara.com/tests/
谢谢!!!!!
这篇关于向下滚动页面后更改元素css位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文