日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

html自动广告业代码,html+javascript实现广告窗自由浮动

發布時間:2025/3/21 javascript 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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实现广告窗自由浮动的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。