时间:2021-07-01 10:21:17 帮助过:21人阅读
js漂浮广告代码具体示例如下:
<body> <div id="img1" onmouseover="pause_resume()" onmouseout="pause_resume()"> <div><a href="javascript:void(0);" onclick="closediv()" title="点击关闭">关闭</a></div> <a href=" " target="_blank"><img src="2.png" alt="可关闭的自由漂浮的图片广告特效代码"></a> </div> <p>网站漂浮代码测试</p> <script type="text/javascript"> var xPos = 300; var yPos = 200; var step = 1; var delay = 30; var height = 0; var Hoffset = 0; var Woffset = 0; var yon = 0; var xon = 0; var pause = true; var interval; var divid = img1; //浮动DIV的ID. divid.style.top = yPos; function changePos(){ width = document.body.clientWidth; height = document.body.clientHeight; Hoffset = divid.offsetHeight; Woffset = divid.offsetWidth; divid.style.left = xPos + document.body.scrollLeft; divid.style.top = yPos + document.body.scrollTop; if(yon){yPos = yPos + step;}else{yPos = yPos - step;} if(yPos < 0){yon = 1;yPos = 0;} if(yPos >= (height - Hoffset)){yon = 0; yPos = (height - Hoffset);} if(xon){xPos = xPos + step;}else{xPos = xPos - step;} if(xPos < 0){xon = 1;xPos = 0;} if(xPos >= (width - Woffset)){xon = 0; xPos = (width - Woffset);} } function start(){ divid.visibility = "visible"; interval = setInterval('changePos()',delay); } function pause_resume(){ if(pause){ clearInterval(interval); pause = false;} else{ interval = setInterval('changePos()',delay); pause = true; } } function closediv(){ clearInterval(interval); divid.style.display = "none"; } start(); </script> </body>
style样式代码如下:
<style type="text/css"> #img1{width:59px;height:61px;position:absolute;top:43px;left:2px;z-index:10;} #img1 div{width:80px;text-align:right;font-size:12px;} #img1 div a:link{text-decoration:none;} #img1 div a:hover{color:red;text-decoration:none;} #img1 img{width:80px;height:80px;border:1px solid black;} p{margin-top:50px;text-align:center;} </style>
以上代码测试如下截图:
以上文章主要介绍了js实现图片漂浮效果的方法,实例分析了js实现图片漂浮的技巧,具有一定参考借鉴价值,需要的朋友可以参考下,这样的特效能够起到着重强调的效果!
【相关文章推荐】
JavaScript实现漂浮广告代码的实例总结
js实现关闭悬浮框广告特效详解
推荐5款实用好看的网页悬浮二维码特效代码
JS实现图片居中悬浮效果实例分享
以上就是网页上怎么让图片出现自由漂动的效果?(js代码示例)的详细内容,更多请关注Gxl网其它相关文章!