<jQuery> <方法> 十五. scrollTop()方法和scrollLeft()方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body {
            width: 2000px;
            height: 2000px;
        }
    </style>
</head>
<body>


<div></div>
<input type="button" value="顶部">
<input type="button" value="左边">
<script src="jquery-3.2.1.js"></script>
<script>
    $(function () {
        $(window).scroll(function () {
            // 距离上边的距离
            console.log($(window).scrollTop());

            // 距离左边的距离
            console.log($(window).scrollLeft());
        });
    });
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body {
            width: 2000px;
            height: 2000px;
        }
    </style>
</head>
<body>


<div></div>
<input type="button" value="顶部">
<input type="button" value="左边">
<script src="jquery-3.2.1.js"></script>
<script>
    $(function () {
        $(window).scroll(function () {
            // 距离上边的距离
            console.log($(window).scrollTop());

            // 距离左边的距离
            console.log($(window).scrollLeft());
        });
    });
</script>
</body>
</html>

 

posted @ 2018-01-12 16:42  云淡风轻我爱编程  阅读(170)  评论(0编辑  收藏  举报