javascript
html自动广告业代码,html+javascript实现广告窗自由浮动
首先介紹一種設置div初始位置的定位方法:
.html代碼如下:
層的移動#ad{width:120px;height:120px;background:url(images/default.gif);position:relative;}
var obj = null;
function init(){
obj = document.getElementById("ad");
obj.style.left="10px";//設置初始位置
obj.style.top="10px";
alert(obj.style.posLeft);//獲得方式一
alert(parseInt(obj.style.left));//獲得方式二
}
function move(){
}
實現廣告窗口在可視范圍內浮動代碼如下:
層的移動#ad{width:120px;height:120px;background:url(images/default.gif);position:relative;}
var id;
var directionX=true,directionY=true;
var x=10,y=10;
var obj = null;
function init(){
obj = document.getElementById("ad");//獲得對象
obj.style.posLeft = x;//對象屬性設置
obj.style.posTop = y;
id = setInterval(move,100);//100ms重復執行move方法
}
function move(){
var width=document.documentElement.clientWidth-obj.offsetWidth;
var height= document.documentElement.clientHeight-obj.offsetHeight;
if(x>=width ){//說明移動到最右邊
directionX = false;
}
if(x==0){//移動到最左邊
directionX = true;
}
if(y >= height){
directionY = false;
}
if(y==0){
directionY = true;
}
if(directionX)
x += 10;
else
x -= 10;
if(directionY)
y += 10;
else
y -= 10;
obj.style.posLeft = x;
obj.style.posTop = y;
}
總結
以上是生活随笔為你收集整理的html自动广告业代码,html+javascript实现广告窗自由浮动的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 本地html自动跳转,HTML页面跳转的
- 下一篇: html中基本选择器的优先级,CSS_C