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)

  • 相关阅读:
    Shell脚本sed命令
    Shell脚本常用unix命令
    Shell的case语句
    3.5.2 数值之间的转换
    3.5.1 数学函数与常量
    3.5 运算符
    3.4.2 常量
    3.4.1 变量初始化
    3.4 变量
    Python异常捕捉的一个小问题
  • 原文地址:https://www.cnblogs.com/linewman/p/9918564.html
Copyright © 2011-2022 走看看