zoukankan      html  css  js  c++  java
  • 小白之返回顶部按钮

    小白之返回顶部按钮

    样式:

    点击按钮后,页面返回顶部。

    步骤:

    步骤:

    1.引入jquery,bootstrap。

     <script src="jquery/jquery-3.1.0.min.js"></script>
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>

    2.制作一个按钮,图标使用bootstrap自带的图标。

    <a href="" id="totop"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span></a>

    3.调样式。

    4.js

     $(function () {
            $(window).scroll(function () {
                if($(this).scrollTop()<200){
                    $("#totop").fadeOut();
                }else{
                    $("#totop").fadeIn();
                }
            });
            $("#totop").hover(function () {
                $(this).html("返回顶部");
            }, function () {
                $(this).html('<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>');
            })
            .on('click', function () {
                        alert("click");
                        $('html,body').animate({scrollTop:0},'fast');
                        return false;
                    })
        })

    html代码展示:

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
        <script src="jquery/jquery-3.1.0.min.js"></script>
        <style>
            body{height: 5000px;background: #ccc;}
            #totop{text-align:center;line-height:50px;font-size:25px;display: block;width:50px;height:50px;position: fixed;top:50px;right: 50px;background: #000;color: #fff;border-radius: 10px;}
            #totop:hover{background: #fff;color: #000;font-size: 10px;}
        </style>
    </head>
    <body>
    <a href="" id="totop"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span></a>
    <script>
        $(function () {
            $(window).scroll(function () {
                if($(this).scrollTop()<200){
                    $("#totop").fadeOut();
                }else{
                    $("#totop").fadeIn();
                }
            });
            $("#totop").hover(function () {
                $(this).html("返回顶部");
            }, function () {
                $(this).html('<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>');
            })
            .on('click', function () {
                        alert("click");
                        $('html,body').animate({scrollTop:0},'fast');
                        return false;
                    })
        })
    </script>
    </body>
    </html>
    View Code
  • 相关阅读:
    salt+jenkins+gitlab+ecs构建公司部署平台
    解决openstack实例主机名后缀问题
    测试CentOS-7-x86_64-Minimal-1708.iso这种光盘安装效果
    dbca建库--linux上使用vnc图形化安装oracle10g版本
    使用mediainfo工具统计每个视频文件(媒体文件)播放时长
    rsync命令简单用法介绍
    winscp工具和xshell连接linux机器时切换到root账户
    zabbix和iptables的nat表结合使用
    adb和机顶盒一些常识
    VirtualBox虚拟机禁止时间同步
  • 原文地址:https://www.cnblogs.com/s313139232/p/7508596.html
Copyright © 2011-2022 走看看