简体   繁体   中英

Javascript code for smooth scroll on website doesn't work after update on Contao version

I made a smooth scroll using JavaScript in my layout, but after refreshing, the script doesn't work.

Every time I have a same error:

Script:

 <script> $(function() { $('a[href*=#]:not([href=#mmenu], [href=#article-38])').click(function() { if (location.pathname.replace(/^\\//,'') == this.pathname.replace(/^\\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top - 100 }, 1000); return false; } } }); }); </script> <script> $(function() { $('a[href=#article-38]').click(function() { if (location.pathname.replace(/^\\//,'') == this.pathname.replace(/^\\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); }); </script> 

And these are the errors:

 Uncaught Error: Syntax error, unrecognized expression: a[href*=#]:not([href=#mmenu], [href=#article-38]) at Function.oe.error (jquery-3.3.1.min.js:2) at oe.tokenize (jquery-3.3.1.min.js:2) at oe.select (jquery-3.3.1.min.js:2) at Function.oe [as find] (jquery-3.3.1.min.js:2) at w.fn.init.find (jquery-3.3.1.min.js:2) at new w.fn.init (jquery-3.3.1.min.js:2) at w (jquery-3.3.1.min.js:2) at HTMLDocument.<anonymous> (home.html:62) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2) jquery-3.3.1.min.js:2 Uncaught Error: Syntax error, unrecognized expression: a[href=#article-38] at Function.oe.error (jquery-3.3.1.min.js:2) at oe.tokenize (jquery-3.3.1.min.js:2) at oe.select (jquery-3.3.1.min.js:2) at Function.oe [as find] (jquery-3.3.1.min.js:2) at w.fn.init.find (jquery-3.3.1.min.js:2) at new w.fn.init (jquery-3.3.1.min.js:2) at w (jquery-3.3.1.min.js:2) at HTMLDocument.<anonymous> (home.html:78) at l (jquery-3.3.1.min.js:2) at c (jquery-3.3.1.min.js:2) 

This is the script that I used in my Contao web site, and after site update, the script doesn't work.

I tried many changes, but none of them worked.

Any suggestions?

Thank you in advance.

This is my smooth menu. It work, but without smooth effect...

 <div id="smoothscroll-menu"> <div id="nav-header" class="scmenu-dot"><p class="tooltip">Start</p><a href="#article-38"></a></div> <div id="nav-cont1" class="scmenu-dot"><p class="tooltip">Page1</p><a href="#cont1"></a></div> <div id="nav-cont2" class="scmenu-dot"><p class="tooltip">Page2</p><a href="#cont2"></a></div> <div id="nav-cont3" class="scmenu-dot"><p class="tooltip">Page3</p><a href="#cont3"></a></div> <div id="nav-cont4" class="scmenu-dot"><p class="tooltip">Page4</p><a href="#cont4"></a></div> <div id="nav-cont5" class="scmenu-dot"><p class="tooltip">Page5</p><a href="#cont5"></a></div> <div id="nav-cont6" class="scmenu-dot"><p class="tooltip">Page6</p><a href="#cont6"></a></div> <div id="nav-partner" class="scmenu-dot"><p class="tooltip">Partner</p><a href="#partner"></a></div> <div id="nav-footer" class="scmenu-dot"><p class="tooltip">Kontakt</p><a href="#footer"></a></div> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM