scrollTo不滚动窗口 [英] scrollTo not scrolling the window

查看:119
本文介绍了scrollTo不滚动窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定为什么这不起作用

I am not sure why this isn't working

html

    <a href="#" id="scrollTop" class="margin-top-40 btn btn-danger btn-lg top btn-not-100">Back to top</a>

jQuery

    $("#scrollTop").on("click",function(e){
      e.preventDefault();
      $(window).animate({scrollTop: 0}, 'slow');
    });

即使尝试了以下结果仍然是负面的

Even tried the following with still negative results

    $("#scrollTop").on("click",function(e){
      e.preventDefault();
      $("body, html").animate({scrollTop: 0}, 'slow');
    });

Css

    html, body {height:100%;}

使用jquery-1.10.2.js,安慰不出现任何错误

Using jquery-1.10.2.js, consolle not giving any error

更新 下面的注释使我理解使用jQuery scrollTop和html的问题,主体设置为溢出...因此

UPDATE Comments below lead me to understand the issue is with using jQuery scrollTop and html, body set to overflow... Because of that a new question has been created here on stack.

推荐答案

解决了这个问题,多亏了我注意到我有body: overflow-x:hidden的评论,这意味着当我们在正文html上使用溢出时,scrollTop无法正常工作

Got the issue, thanks to comments I noticed I had body: overflow-x:hidden which means scrollTop isn't working when we are using overflow on body, html

这篇关于scrollTo不滚动窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆