onClick 使用 jQuery .animate 转到页面底部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11188584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
onClick go to the bottom of page using jQuery .animate
提问by mcmwhfy
I have a table where last column contains action buttons which opens another section under the table. When that section is opened the body page remain where the button from action column was pressed. I need to use a jQuery preferably with .animate which scrolls .html page to that opened section under the table.
我有一个表格,其中最后一列包含操作按钮,可在表格下方打开另一部分。当该部分打开时,正文页面仍保留在按下操作列中的按钮的位置。我需要最好使用带有 .animate 的 jQuery,它将 .html 页面滚动到表格下的打开部分。
fiddle example: http://jsfiddle.net/Ksb2W/110/
小提琴示例:http: //jsfiddle.net/Ksb2W/110/
If anyone cand help me with this. Thank you.
如果有人可以帮我解决这个问题。谢谢你。
回答by Tats_innit
demohttp://jsfiddle.net/h4ZQR/orhttp://jsfiddle.net/byRRY/
演示http://jsfiddle.net/h4ZQR/或http://jsfiddle.net/byRRY/
Good API: http://api.jquery.com/scrollTop/
好的 API:http: //api.jquery.com/scrollTop/
Please note: you can use: .animate({scrollTop: $("#whateverdiv").offset().top});
to go to certain sections of page.
请注意:您可以使用:.animate({scrollTop: $("#whateverdiv").offset().top});
转到页面的某些部分。
Hope this helps
希望这可以帮助
html
html
<a href="#bottom" id="hulk">Click me to go to bottom</a>
code
代码
$("#hulk").click(function() {
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
});?
OR
或者
$("a[href='#bottom']").click(function() {
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
return false;
});?