javascript - background color added at specific scroll level? -


I want the background of my navigation to be transparent on the landing page, but when users scroll over the front of the page , I want to display the background of the navigation, then when they scroll back up, this way (without the slide effect) falls

The scrolling position of the element that you want to scroll You must evaluate and evaluate the position on the page of those elements that you want to trigger. Here's an example with Jacquery, but it can be easily done in Vanilla JS too.

CSS

  html, body {height: 100%; Width: 100%; Margin: 0; Padding: 0; } Section {height: 220px; } Nav {position: fixed; Top: 0; Left: 0; Width: 100%; Height: 20px; Border: 1px solid # 888; }   

HTML

  & lt; Div id = "main" & gt; & Lt; Section data-color = "transparent" & gt; Section 0 & lt; / Section & gt; & Lt; Section data-color = "# F60000" & gt; Section 1 & lt; / Section & gt; & Lt; Section data-color = "# 00f600" & gt; Section 2 & lt; / Section & gt; & Lt; Section data-color = "# 0000f6" & gt; Section 3 & lt; / Section & gt; & Lt; Section data-color = "# FF99 66" & gt; Section 4 & lt; / Section & gt; & Lt; Section data-color = "# 66ff99" & gt; Section 5 & lt; / Section & gt; & Lt; Section data-color = "# 9966ff" & gt; Section 6 & lt; / Section & gt; & Lt; Section data-color = "# 669 9ff" & gt; Section 7 & lt; / Section & gt; & Lt; / Div & gt; & Lt; NAV & gt; & Lt; / Neo & gt;   

JS

  var $ window = $ (window), $ nav = $ ('nav'), $ squares = $ ('section') $ Window On ("scroll", onskol); Function onskol (e) {$ sections.each (function () {var $ section = $ (this); if ($ section.offset (). Top- $ window.scrollTop () & lt; 0) {$ nav Css ('background color', $ section.data ('color'))}}}}}    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -