html图片怎么设置悬浮效果,图片漂浮效果js实现
當(dāng)鼠標在圖片上方時,圖片停止漂浮,點擊關(guān)閉按鈕可隱藏圖片。
var xPos=0;
var yPos=0;
var directionX=true;
var directionY=true;
var step=1;
var speed=1;
var float=document.getElementById("float");
function move(){
var height=document.documentElement.clientHeight;
var width=document.documentElement.clientWidth;
var imgHeight=float.offsetHeight;
var imgWidth=float.offsetWidth;
float.style.left=xPos+document.documentElement.scrollLeft+"px";
float.style.top=yPos+document.documentElement.scrollTop+"px";
if(directionX){xPos=xPos+step;}else{xPos=xPos-step;}
if(xPos<=0){xPos=0;directionX=true;}
if(xPos>=width-imgWidth){xPos=width-imgWidth;directionX=false;}
if(directionY){yPos=yPos+step;}else{yPos=yPos-step;}
if(yPos<=0){yPos=0;directionY=true;}
if(yPos>=height-imgHeight){yPos=height-imgHeight;directionY=false;}
t=setTimeout(move,speed);
}
float.οnmοuseοver=function(){clearTimeout(t);}
float.οnmοuseοut=function(){t=setTimeout("move()",speed);}
window.οnlοad=move();
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的html图片怎么设置悬浮效果,图片漂浮效果js实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 什么是房产沉降差?
- 下一篇: ie统计报表html,IE中动态添加表格