weixin_33697898 2012-08-29 19:25 采纳率: 0%
浏览 64

滚动到顶部不起作用

Hello I am new to jQuery and I have a problem! I want to scroll to the top, in a page that is loaded via AJAX call.

This works (test):

$(document).on('click', '#top_icon', function() {
    alert('ok');
});

But this is not working (this is what I want to achieve):

$(document).on('click', '#top_icon', function() {
    $('html, body').animate({scrollTop: '0px'}, 800);
});
  • 写回答

2条回答 默认 最新

  • elliott.david 2012-08-29 19:27
    关注

    Try this,

    $(document).on('click', '#top_icon', function() {
        $('html, body').animate({'scrollTop': '0px'}, 800);
        return false;
    });
    

    scrollTop is undefined in your case.

    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码