参考: Cascading Style Sheet 2.0 中文手册_.chm
3. body.clientWidth / body.clientHeigth
<body><div id="sunDiv"><img src=".jpg" /></div></body>
<style type="text/css">body {/*背景图 501 * 500 pixels*/background-image: url(-1A2153AC6853FFE52D9C0142F24AF424.jpg);/*背景图不够大时, 不重复*/background-repeat : no-repeat;
}#sunDiv {position: absolute;background-color: gray;
}#sunDiv img {width: 40px;height: 40px;
}</style>
<script type="text/javascript">// 两个方向var directX = 1; // x轴方向var directY = 1; // y轴方向// 太阳的坐标var sunX = 0;var sunY = 0;// 速度var interval = 10;var sunDiv; // load = function() {sunDiv = ElementById("sunDiv");window.setInterval(move, interval);} function move() {// 改变坐标sunX += directX;sunY += directY;// 改变位置p = sunY + "px";sunDiv.style.left = sunX + "px";// 转变方向,if ( sunX + sunDiv.offsetWidth >= 520 || sunX < 0 ) {directX = - directX;}if ( sunY + sunDiv.offsetHeight >= 500 || sunY < 0 ) {directY = - directY;} }</script>
本文发布于:2024-01-27 20:05:42,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063571402354.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |