jQuery滚动到“不工作”
当我点击箭头时,我试图让我的网站向下滚动。可以在这里查看 然而,由于某些原因,单击时什么也没有发生。这根本不起作用。我在其他部门也试过,但运气不好jQuery滚动到“不工作”,jquery,html,drop-down-menu,responsive-design,scroll,Jquery,Html,Drop Down Menu,Responsive Design,Scroll,当我点击箭头时,我试图让我的网站向下滚动。可以在这里查看 然而,由于某些原因,单击时什么也没有发生。这根本不起作用。我在其他部门也试过,但运气不好 <script> $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,''
<script>
$(function() {
$('a[href*=#]:not([href=#])').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>
$(函数(){
$('a[href*=#]:非([href=#])。单击(函数(){
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(目标长度){
$('html,body')。设置动画({
scrollTop:target.offset().top
}, 1000);
返回false;
}
}
});
});
希望有人能帮忙
谢谢,丹佛我检查了你的DOM元素,没有ul之类的例子。 在本例中,请参见具有以下结构的名称的本例DOM元素,您必须在站点中创建类似的内容:
<div id="page-wrap">
<h1 id="top">Smooth Page Scrolling</h1>
...
<ul>
<li><a href="/examples/SmoothPageScroll/#two">Scroll to Section Two</a></li>
<li><a href="#three">Scroll to Section Three</a></li>
</ul>
<h1 id="one">Section One</h1>
...
<h1 id="two">Section Two</h1>
...
<p><a href="#top">Top</a></p>
</div>
平滑页面滚动
...
第一节
...
第二节
...
发生这种情况是因为#circlediv
内的标记不可见(宽度和高度等于零)
您必须做的是用a
元素包装#circlediv
,如下所示:
<div class="upper">
<a href="#article">
<div id="circlediv">
</div>
</a>
</div>
我现在查看了您的页面,发现:
您的
其次,您没有任何具有id='article'
的元素,因此它找不到任何可滚动到的元素。检查target.length
,在控制台中运行代码的几个链接上快速测试返回0
。设置一个断点并单步执行代码嗯,它仍然不想加载什么?我再次检查了你的网站,它成功了!我遗漏了什么吗?啊,可能是缓存吗?
<a href="#article">
<div id="circlediv">
</div>
</a>