sticky nav

User 450830 Photo


Registered User
148 posts

Hi, I want to create a sticky nav menu in sd5 under Materialize. Is that possible.
groet,

Ger van Veen
http://schilder-vanveen.nl
User 122279 Photo


Senior Advisor
14,454 posts

Do you mean something like this https://eikweb.com/sharing/ma-sticky/index.html ? Check out my sharing site, or my new site with ready-made components. Both URLs in my signature.
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 450830 Photo


Registered User
148 posts

No see this
https://www.w3schools.com/howto/howto_js_navbar_sticky.asp

I just can't get this working
groet,

Ger van Veen
http://schilder-vanveen.nl
User 122279 Photo


Senior Advisor
14,454 posts

In principle, it is working the same way. I've never tried that one in Materialize, but I could try...
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 2699991 Photo


Registered User
4,803 posts
Online Now

Ger van veen wrote:
No see this
https://www.w3schools.com/howto/howto_js_navbar_sticky.asp

I just can't get this working


You need add the css style to your page header

<style>.sticky {
position: fixed !important;
top: 0 !important;
width: 100%;
}</style>

Do Not add a class "sticky" to the container you want to be sticky

Add the JS script fo your page footer
<script>// When the user scrolls the page, execute myFunction
window.onscroll = function() {myFunction()};

// Get the navbar
var navbar = document.getElementById("navbar");

// Get the offset position of the navbar
var sticky = navbar.offsetTop;

// Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}</script>
Mastering The Understanding With Hands-On Learning
NEW TO "COFFEECUP SITE DESIGNER" FOUNDATION 6 FRAMEWORK?
STUCK ON SOMETHING?

LEARNING & UNDERSTANDING "THE HOW TO"? THE WHY'S & THE WHEREFORE'S?
WITH WAYAN'S STEP BY STEP TUTORIALS
Contact Me For One To One Assistance
https://alphathemes.coffeecup.com/forms … an%281%29/
User 122279 Photo


Senior Advisor
14,454 posts

Ger, try this one.
Attachments:
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 2699991 Photo


Registered User
4,803 posts
Online Now

Wayan Jaya wrote:
Ger van veen wrote:
No see this
https://www.w3schools.com/howto/howto_js_navbar_sticky.asp

I just can't get this working


You need add thefollowing css style to your page header

<style>.sticky {
position: fixed !important;
top: 0 !important;
width: 100%;
}</style>

Do Not add a class "sticky" to the container you want to be sticky
Update
I Forgot to add that you should give the container an ID = navbar

Add the following JS script fo your page footer
<script>// When the user scrolls the page, execute myFunction
window.onscroll = function() {myFunction()};

// Get the navbar
var navbar = document.getElementById("navbar");

// Get the offset position of the navbar
var sticky = navbar.offsetTop;

// Add the sticky class to the navbar when you reach its scroll position. Remove "sticky" when you leave the scroll position
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}</script>


Ingers way works also, but this way you don't need add an HTML element, just the CSS and JS files
Mastering The Understanding With Hands-On Learning
NEW TO "COFFEECUP SITE DESIGNER" FOUNDATION 6 FRAMEWORK?
STUCK ON SOMETHING?

LEARNING & UNDERSTANDING "THE HOW TO"? THE WHY'S & THE WHEREFORE'S?
WITH WAYAN'S STEP BY STEP TUTORIALS
Contact Me For One To One Assistance
https://alphathemes.coffeecup.com/forms … an%281%29/
User 2699991 Photo


Registered User
4,803 posts
Online Now

Here is a short silent demo movie showing the materialize theme theme "save the planet" with the CSS & JS files in place

https://youtu.be/qVa23V59Ekw
Mastering The Understanding With Hands-On Learning
NEW TO "COFFEECUP SITE DESIGNER" FOUNDATION 6 FRAMEWORK?
STUCK ON SOMETHING?

LEARNING & UNDERSTANDING "THE HOW TO"? THE WHY'S & THE WHEREFORE'S?
WITH WAYAN'S STEP BY STEP TUTORIALS
Contact Me For One To One Assistance
https://alphathemes.coffeecup.com/forms … an%281%29/
User 122279 Photo


Senior Advisor
14,454 posts

Wayan Jaya wrote:


Ingers way works also, but this way you don't need add an HTML element, just the CSS and JS files


I'm so used to HTML elements because of creating components. Of course, you can add the CSS and js to the page manager instead.
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 450830 Photo


Registered User
148 posts

Thank you Wayan Jaya for your clear explanation. it works now
groet,

Ger van Veen
http://schilder-vanveen.nl

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.