我想计算底部的窗口滚动位置。并希望在窗口的右上角看到结果。为此,我的代码就像下面一样:
jQuery(document).ready(function(){
jQuery(window).scroll(function(){
var windowHeight = jQuery(window).height();
var windowScrollPosTop = jQuery(window).scrollTop();
var windowScrollPosBottom = windowHeight + windowScrollPosTop;
var objectOffset = jQuery(".example-photo").offset();
var objectOffsetTop = objectOffset.top;
jQuery(".status").html(objectOffsetTop);
});
});
.status{
background: #FFF;
color: #000;
padding: 15px;
position: fixed;
top: 0;
right: 0;
z-index: 900;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="status"></div>
<div class="container">
<p>Paragraphp</p>
<img class="example-photo" src="location/image.jpg" alt="demo" />
</div>
<body>
问题:当我调整浏览器大小时,滚动位置不会改变。我认为应该在缩小或增加浏览器大小时进行更改。我在哪里做错了?