zoukankan      html  css  js  c++  java
  • js实现返回页面顶部

    无动态效果

    1、原生JS

    window.scrollTo(0,0);


    2、jQuery

    $(window).scrollTop(0);


    有动态效果

    1、原生JS

    function smoothscroll(){   
             window.requestAnimationFrame(smoothscroll);  
             window.scrollTo (0,currentScroll - (currentScroll/5));  
    }

    2、jQuery

    $('html,body').animate({scrollTop:0},200);
    if($('html').scrollTop()){
        $('html').animate({scrollTop:0},200);
        return false;
    }
    $('body').animate({scrollTop:0},200);
    return false;

    注意:将代码放入click事件的函数,或者执行函数,就能执行,返回顶部。

    其他

    [我的博客,欢迎交流!](http://rattenking.gitee.io/stone/index.html)

    [我的CSDN博客,欢迎交流!](https://blog.csdn.net/m0_38082783)

    [微信小程序专栏](https://blog.csdn.net/column/details/18335.html)

    [前端笔记专栏](https://blog.csdn.net/column/details/18321.html)

    [微信小程序实现部分高德地图功能的DEMO下载](http://download.csdn.net/download/m0_38082783/10244082)

    [微信小程序实现MUI的部分效果的DEMO下载](http://download.csdn.net/download/m0_38082783/10196944)

    [微信小程序实现MUI的GIT项目地址](https://github.com/Rattenking/WXTUI-DEMO)

    [微信小程序实例列表](http://blog.csdn.net/m0_38082783/article/details/78853722)

    [前端笔记列表](http://blog.csdn.net/m0_38082783/article/details/79208205)

    [游戏列表](http://blog.csdn.net/m0_38082783/article/details/79035621)

  • 相关阅读:
    情书2
    情书1
    python_数据分析_正态分布
    python3调用R语言干货
    常见混淆名词
    PID算法图形 python
    A*寻路算法 python实现
    用tensorflow object detection api做手势识别
    tf识别非固定长度图片ocr(数字+字母 n位长度可变)- CNN+RNN+CTC
    tf识别固定长度验证码图片ocr(0到9 4位)- CNN方式
  • 原文地址:https://www.cnblogs.com/linewman/p/9918564.html
Copyright © 2011-2022 走看看