我在布局中使用JavaScript进行了平滑滚动,但是刷新后,脚本不起作用。
每次我都有同样的错误:
脚本:
<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>
这些是错误:
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)
这是我在 Contao 网站中使用的脚本,站点更新后,该脚本不起作用。
我尝试了许多更改,但没有一个有效。
有什么建议吗?
提前谢谢你。
这是我
流畅的菜单。它有效,但没有平滑的效果...
<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>