首页 > js的运动问题,和视频说的不一样

js的运动问题,和视频说的不一样

html====

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="style/main.css">
</head>
<body style="height:1000px">
<div id="box"></div>
</body>
</html>
<script src="js/jquery-1.11.2.js"></script>
<script src="js/demo.js"></script>  

css

#box{width: 100px;height: 100px;background: red url() 0 0 no-repeat;position: absolute;bottom: 0;right: 0;  }

js

window.onscroll=function  () {
    var obj=document.getElementById('box');
    var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
    obj.style.top=document.documentElement.clientHeight-obj.offsetHeight+scrollTop+"px";
}

为什么我滚动一下图片就消失了,而视频是随着滚动的


使用jQuery的写法:

$('#box').animate({'top': documentElement.clientHeight - obj.height() + scrollTop + 'px'}, 'slow');


html 文件头部添加 <!DOCTYPE html> 声明

【热门文章】
【热门文章】