如何在另一个HTML网站上创建指向长网页的一部分的链接?
我的问题是,我有两个HTML页面:index.html?Site=Info
。
当我制作一个"跳转链接"它不起作用。与#
。有什么想法吗?
答案 0 :(得分:2)
如果您要链接的部分已将set.animation添加到效果
,则片段锚应该有效
$(document).ready(function(){
$(".anchor").click(function(e){
$('html, body').animate({
scrollTop: $($(this).attr('href')).offset().top
}, 1000);
});
});
#top{background-color:red;}
#middle{background-color:yellow;}
#bottom{background-color:green;}
div.block{height:400px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="toppage"></div>
<a class="anchor" href="#top">
<div class="arrow-down-light-blue">top</div>
</a>
<a class="anchor" href="#middle">
<div class="arrow-down-light-blue">middle</div>
<a class="anchor" href="#bottom">
<div class="arrow-down-light-blue">bottom</div>
</a>
<div class="block" id="top">The top
<a class="anchor" href="#toppage"> Back to top</a>
</div>
<div class="block" id="middle">The middle
<a class="anchor" href="#toppage"> Back to top</a>
</div>
<div class="block" id="bottom">The bottom
<a class="anchor" href="#toppage"> Back to top</a>
</div>