scrollTop上移和下移

来源:互联网 发布:中国五矿待遇知乎 编辑:程序博客网 时间:2024/06/06 04:28
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <style>
        textarea {
            width:200px;height:100px;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<meta charset="utf-8" />
</head>
<body>
    <div> <span class="xx">向下</span><span class="xs">向上</span></div>
    <br />
    <hr />
    <textarea id="id1">
        123。
    </textarea>
    <script>
        $(function () {
            var $er = $("#id1");      
            $(".xs").click(function () {
                if (!$er.is(":animated")) {
                    if ($er.scrollTop() > 50) {
                        $er.animate({ scrollTop: "-=50" }, 1000);
                    }
                }
            });
            $(".xx").click(function () {
                if (!$er.is(":animated")) {
                    if ($er.scrollTop() < 500) {
                        $er.animate({ scrollTop: "+=50" }, 1000);
                    }
                }
            });
        })
    </script>
</body>
</html>
原创粉丝点击