我已经检查过这里的其他帖子,没有我正在寻找的结果。
我想点击
<a href="#about">About</a>
<div id="about">Content of this..</div>
并让它滚动到该元素,而不将 www.domain.com/#about 放入地址栏中
作为一个完美的例子,请查看我发现的这个网站here http://thinkpixellab.com然后单击一些链接——单击时它们不会更改地址栏。
您可以使用 javascript 和 jquery 执行您想要的操作,如下所示(请注意,这是使用旧版本的 jquery):
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type='text/javascript'>
jQuery(document).ready(function($) {
$(".scroll").click(function(event){
event.preventDefault();
$('html,body').animate({scrollTop:$(this.hash).offset().top}, 1200);
});
});
</script>
</head>
<body>
<a class="scroll" href="#codeword">Blue Words</a>
<div id="codeword"></div>
</body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)