如何滚动到按钮单击页面的顶部? [英] How to scroll back to the top of page on button click?
问题描述
我使用对象代码创建产品页面,但每次点击查看按钮时,下一页都停留在刚刚查看的上一页的相同位置。每次点击查看按钮时,如何添加可让我从页面顶部查看的功能?
<< ; div id =containerclass =clearfix><! - ! #sidebar结尾 - >
< div class =持有人>< / div>
< div id =contentclass =defaults><! - navigation holder - >
< div id =title2> Office部分< / div>
<! - - 物品容器 - >
< ul id =itemContainer>
< li>
< div id =product>
< div id =title>FuBang®< / div>
< div class =imageOuterstyle =margin:0>
< a class =imagehref =officesection010.html>
< span class =rollover>< / span>
< img class =imgbordersrc =product / officesection / 010.jpgwidth =165height =165/>
< / a>
< / div>< br />
< div id =text>沙发< / div>< br />
< div id =button>
< a href =officesection010.html>查看详情< / a>
< / div>
< / div>
< / li>
< / ul>
< br />
< div id =title2>< / div>
< div class =持有人>< / div>
< / div>
< / div> <! - ! #内容结束 - >
< / div> <! - ! #container结尾 - >
当我在这里点击特定位置x处的View Details按钮时: http://postimg.org/image/vgs0lwhtr/
下一页显示相同的位置x,但我希望它跳转到页面顶部:
http://postimg.org/image/vn80e2lph/
使用Javascript:
document.body.scrollTop = document.documentElement.scrollTop = 0;
使用jQuery:
$(function(){
$('body')。scrollTop(0);
});
I am creating my product pages by using the object tag code, but every time I click the "view" button, the next page is staying at the same position of previous page which I just viewed. How can I add functionality that will let me view from the top of page every time I click the "view" button?
<div id="container" class="clearfix"><!--! end of #sidebar -->
<div class="holder"></div>
<div id="content" class="defaults"><!-- navigation holder -->
<div id="title2">Office Section</div>
<!-- item container -->
<ul id="itemContainer">
<li>
<div id="product">
<div id="title">FuBang®</div>
<div class="imageOuter" style="margin:0">
<a class="image" href="officesection010.html">
<span class="rollover" ></span>
<img class="imgborder" src="product/officesection/010.jpg" width="165" height="165" />
</a>
</div><br />
<div id="text">Sofa </div><br />
<div id="button">
<a href="officesection010.html">View Details</a>
</div>
</div>
</li>
</ul>
<br />
<div id="title2"></div>
<div class="holder"></div>
</div>
</div> <!--! end of #content -->
</div> <!--! end of #container -->
When I click the "View Details" button at a specific position "x" here: http://postimg.org/image/vgs0lwhtr/
The next page shows the same position "x", but I want it to jump to the top of page: http://postimg.org/image/vn80e2lph/
Using Javascript:
document.body.scrollTop = document.documentElement.scrollTop = 0;
Using jQuery:
$(function() {
$('body').scrollTop(0);
});
这篇关于如何滚动到按钮单击页面的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!