[英]Scroll Website - I want my navigation div change color when scroll pass a section
I am not using any frameworks. 我没有使用任何框架。 How can I make my navigation div change color each time I scroll through a section on my page?
每次滚动页面上的某个部分时,如何使导航div更改颜色?
This is my web page: http://www.noteid.com/scl 这是我的网页: http : //www.noteid.com/scl
As you can see there is a nav on the left and position: fixed;
如您所见,左侧有导航栏,
position: fixed;
. 。 How can I do this in Javascript?
如何使用Javascript执行此操作?
It you need to use the scroll event. 您需要使用滚动事件。
window.onscroll = function() {
var element = document.getElementById('testDiv');
if (window.pageYOffset > 400 && window.pageYOffset < 800)
element.style.backgroundColor = 'blue';
};
This uses the pageYOffset property to set the background property. 这使用pageYOffset属性设置background属性。
I would use Bootstrap's ScrollSpy to do things like this. 我会用Bootstrap的ScrollSpy来做这样的事情。
http://getbootstrap.com/javascript/#scrollspy http://getbootstrap.com/javascript/#scrollspy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.