現(xiàn)在網(wǎng)上流行會(huì)彈來(lái)彈去的浮動(dòng)圖片。想給自己的網(wǎng)頁(yè)也加上一個(gè)嗎?其實(shí)很簡(jiǎn)單,把下面這段代碼加到網(wǎng)頁(yè)的之間,然后,把圖片換成你中意的就OK啦!
到這里下載示例代碼
< div id="img">
< a target="_blank">
< img
src="/Article/UploadPic/2005-7/20057504250720.gif">
< /a>
<
/div>
< script LANGUAGE="Javascript">
< !-- Begin
var xPos = 20;
var yPos = document.body.clientHeight;
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;
img.style.top = yPos;
function changePos() {
width =
document.body.clientWidth;
height = document.body.clientHeight;
Hoffset
= img.offsetHeight;
Woffset = img.offsetWidth;
img.style.left = xPos +
document.body.scrollLeft;
img.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() {
img.visibility = "visible";
interval =
setInterval(´changePos()´, delay);
}
start();
// End -- >
< /script >[@more@]
網(wǎng)頁(yè)名稱(chēng):JavaScript制作會(huì)反彈的浮動(dòng)圖片(轉(zhuǎn))-創(chuàng)新互聯(lián)
分享網(wǎng)址:
http://weahome.cn/article/dcieoi.html