Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

手机端怎么实现返回顶部效果呢?(手机端滚动条会隐藏,无法检测)我用的sui 框架 a的锚点功能不能用,有没有js方法?

如题,因为用了sui框架,a的锚点链接效果没作用,虽然我禁用了路由功能,还是不行 请问有没有js方法实现返回顶部?或者哪位大神熟悉sui框架 我该怎么实现呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
    //当滚动条的位置处于距顶部100像素以下时,跳转链接出现,否则消失
    $(function () {
        $(window).scroll(function () {
            if ($(window).scrollTop() > 100) {
                $("#back-to-top").fadeIn(1000);
                console.log($(window).scrollTop())
                console.log(window.innerHeight)
            }
            else {
                $("#back-to-top").fadeOut(1000);
            }
        });
        //当点击跳转链接后,回到页面顶部位置
        $("#back-to-top").click(function () {
            $('body,html').animate({scrollTop: 0}, 1000);
            return false;
        });
    });

我写了小demo 明明就可以触发

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="robots" content="all">
    <meta name="renderer" content="webkit">
    <style>
        *{
            margin: 0;padding: 0;
        }
      div{
          width: 100%;
          height:1880px;
          background: #BDBDBD;
      }
        .fix{
            width: 50px;
            height:50px;
            background: #B72712;
            position: fixed;
            right: 0;
            bottom: 50px;
            color: #ffffff;
            font-size: 18px;
            text-align: center;
            display: none;
        }
    </style>
</head>
<body>
<div id="div">
 我是主体内容
</div>
<div class="fix" id="back-to-top">
  返回顶部
</div>
</body>
<script src="jquery.js"></script>
<script>
$(function () {
    $(window).scroll(function () {
        if ($(window).scrollTop() > 100) {
            $("#back-to-top").fadeIn(1000);
            console.log($(window).scrollTop())
            console.log(window.innerHeight)
        }
        else {
            $("#back-to-top").fadeOut(1000);
        }
    });
    //当点击跳转链接后,回到页面顶部位置
    $("#back-to-top").click(function () {
        $('body,html').animate({scrollTop: 0}, 1000);
        return false;
    });
});

</script>
</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...