【问题标题】:onClick go to the bottom of page using jQuery .animateonClick 使用 jQuery .animate 转到页面底部
【发布时间】:2012-06-26 15:56:26
【问题描述】:

我有一个表格,其中最后一列包含操作按钮,可在表格下方打开另一个部分。打开该部分时,正文页面保留在按下操作列中的按钮的位置。我需要使用带有 .animate 的 jQuery,它将 .html 页面滚动到表格下打开的部分。

小提琴示例:http://jsfiddle.net/Ksb2W/110/

如果有人能帮我解决这个问题。 谢谢。

【问题讨论】:

  • to that opened section under the table. 是什么意思?在哪里?
  • 在我的小提琴中,我没有任何动作按钮...

标签: jquery html css jquery-animate


【解决方案1】:

演示 http://jsfiddle.net/h4ZQR/ http://jsfiddle.net/byRRY/

好的 API:http://api.jquery.com/scrollTop/

请注意:您可以使用:.animate({scrollTop: $("#whateverdiv").offset().top}); 转到页面的某些部分。

希望对你有帮助

html

<a href="#bottom" id="hulk">Click me to go to bottom</a>

代码

$("#hulk").click(function() {
  $("html, body").animate({ scrollTop: $(document).height() }, "slow");

});​

$("a[href='#bottom']").click(function() {
  $("html, body").animate({ scrollTop: $(document).height() }, "slow");
  return false;
});​

【讨论】:

  • 对于“hulk” id,您必须提供一个 margin-top 或来自 css 的东西。
  • @RulerNature 是的 :) ,如果需要使用 css,谢谢
  • @mcmwhfy 很高兴它有帮助,:)
【解决方案2】:

这对我有用

$("document").ready(function() {
        $("#button").click(function() {
            $("html, body").animate({
                    scrollTop: innerHeight,
                },
                "slow"
            );
            return false;
        });
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-27
    • 2012-03-15
    • 2023-04-07
    • 2011-05-14
    • 2014-01-11
    • 1970-01-01
    • 2017-09-22
    • 1970-01-01
    相关资源
    最近更新 更多