I cannot use the .animate jQuery method with Google Material Design Lite (MDL). I used MDL to create a navigation bar, but smooth scrolling did not work.
Simple jQuery code:
$(function(){ $('a.smooth').click(function(){ console.log("SMOOTH BEGIN"); var speed = 1000; var href= $(this).attr("href"); var target = $(href == "#" || href == "" ? 'html' : href); var position = target.offset().top; $("html, body").animate({scrollTop:position}, speed, "swing"); console.log("SMOOTH END"); }); });
And a simple html code:
<nav class="mdl-navigation"> <a class="mdl-navigation__link" href="">Home</a> <a class="mdl-navigation__link smooth" href="#product">Product</a> </nav> <main class="mdl-layout__content"> <div id="product"><!—-Contents-—></div> </main>
This code showed me the magazine "SMOOTH BEGIN" and "SMOOTH END". However, this link worked like a regular link, not a smooth one. How can I get jQuery to work with MDL? Some conflicts may occur, but the console does not show anything.
source share