0

I'm new at magento. I'm using luma theme as a blank. I want to fix header and mega menu when page scroll down. Thanks for your helps.

3 Answers 3

0

Have you tried position:fixed in css file?

frontend/Magento/luma/en_US/css/styles-l.css

0
0

Create a custom.js file and place it in your app/design/Custom/theme/web/js folder. Then, from Magento_Theme/layout/default_head_blocks.xml link to your custom JS file like this:

<head>
    <link src="js/custom.js" />
</head>

Alternatively, you can place the link in Admin >> Content >> Configuration > on the default scope to the right of your theme name click on "edit". Open the HTML head tab and in the "Scripts and Style Sheets" box place your script link.

Inside your custom.js file add the following code:

$(document).ready(
        function() {
   var  mn = $(".page-header");
   var mns = "main-nav-scrolled";

$(window).scroll(function() {
 if( $(this).scrollTop() > 0 ) {
   mn.addClass(mns);
 } else {
   mn.removeClass(mns);
  }
}); 
});

Use css class .main-nav-scrolled to style the fixed menu and add any transitions and animations.

0

You can fix this by using css trick position:fixed, because this is css work.

Hope this can be helpful :)

Thanks Ketan T.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.