javascript 简单滚动图片

来源:互联网 发布:淘宝怎么好友代付 编辑:程序博客网 时间:2024/05/01 11:31
<!DOCTYPE html><html ><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script>window.onload=function(){function ad(){var owidth=document.body.offsetWidth;//body 的宽度var oimg=document.getElementById("img"); //图片的宽度var aWidth=owidth-oimg.offsetWidth; //可以移动的区域的宽度oimg.style.position="absolute";//绝对定位oimg.style.left=oimg.offsetLeft+1+"px";//每次移动一个像素/*********** 注意 offsetLeft获取的是 数值 不带单位,left 带单位,这里需要灵活运用* body.offsetWidth获取 body的宽度*  oImg.offsetWidth获取图片的宽度*   两个相减就 获得能移动的宽度*  如果 offsetLeft>可移动宽度,那就复原 left="0px"******/if(oimg.offsetLeft>=aWidth) oimg.style.left="0px";;}var interval=null;interval=setInterval(ad,10);//暂停与停止document.getElementById("img").onmouseover=function(){clearInterval(interval);}document.getElementById("img").onmouseout=function(){interval=setInterval(ad,10);}}</script></head><body><img src="F:\杂七杂八\rg1.jpg" id="img" style="width:250px;height:250px;"/></body></html>

0 0