用HTML做网页怎样添加漂浮物

用HTML做网页怎样添加漂浮物,第1张

用javascript代码编写,你去网上搜,有现成的代码,下面给你一段:漫天飞舞的泡泡

<body>

<script language="JavaScript">

<!--

var no = 30//泡泡的数量

var speed = 1

var ns4up = (document.layers) ? 1 : 0

var ie4up = (document.all) ? 1 : 0

var s, x, y, sn, cs

var a, r, cx, cy

var i, doc_width = 800, doc_height = 600

if (ns4up) {

doc_width = self.innerWidth

doc_height = self.innerHeight

}

else

if (ie4up) {

doc_width = document.body.clientWidth

doc_height = document.body.clientHeight

}

x = new Array()

y = new Array()

r = new Array()

cx = new Array()

cy = new Array()

s = 8

for (i = 0i <no++ i) {

initRain()

if (ns4up) {

if (i == 0) {

//以下有些是对泡泡的颜色及泡泡符号的设置,○改为别的,那么往下掉的就不是泡泡了

document.write("<layer name=\"dot"+ i +"\" left=\"1\" ")

document.write("top=\"1\" visibility=\"show\"><font color=\"#99CCFF\">")

document.write("○</font></layer>")

}

else {

document.write("<layer name=\"dot"+ i +"\" left=\"1\" ")

document.write("top=\"1\" visibility=\"show\"><font color=\"#99CCFF\">")

document.write("○</font></layer>")

}

}

else

if (ie4up) {

if (i == 0) {

document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ")

document.write("absoluteZ-INDEX: "+ i +"VISIBILITY: ")

document.write("visibleTOP: 15pxLEFT: 15px\"><font color=\"#99CCFF\">")

document.write("○</font></div>")

}

else {

document.write("<div id=\"dot"+ i +"\" style=\"POSITION: ")

document.write("absoluteZ-INDEX: "+ i +"VISIBILITY: ")

document.write("visibleTOP: 12pxLEFT: 12px\"><font color=\"#99CCFF\">")

document.write("○</font></div>")

}

}

}

function initRain() {

a = 6

r[i] = 1

sn = Math.sin(a)

cs = Math.cos(a)

cx[i] = Math.random() * doc_width + 1

cy[i] = Math.random() * doc_height + 1

x[i] = r[i] * sn + cx[i]

y[i] = cy[i]

}

function makeRain() {

r[i] = 1

cx[i] = Math.random() * doc_width + 1

cy[i] = 1

x[i] = r[i] * sn + cx[i]

y[i] = r[i] * cs + cy[i]

}

function updateRain() {

r[i] += s

x[i] = r[i] * sn + cx[i]

y[i] = r[i] * cs + cy[i]

}

function raindropNS() {

for (i = 0i <no++ i) {

updateRain()

if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {

makeRain()

doc_width = self.innerWidth

doc_height = self.innerHeight

}

document.layers["dot"+i].top = y[i]

document.layers["dot"+i].left = x[i]

}

setTimeout("raindropNS()", speed)

}

function raindropIE() {

for (i = 0i <no++ i) {

updateRain()

if ((x[i] <= 1) || (x[i] >= (doc_width - 20)) || (y[i] >= (doc_height - 20))) {

makeRain()

doc_width = document.body.clientWidth

doc_height = document.body.clientHeight

}

document.all["dot"+i].style.pixelTop = y[i]

document.all["dot"+i].style.pixelLeft = x[i]

}

setTimeout("raindropIE()", speed)

}

if (ns4up) {

raindropNS()

}

else

if (ie4up) {

raindropIE()

}

-->

</script>

</body>

修改了!你应该是希望滚动条不管在什么位置 这个层都是可见的对吧? 最原始的那个可以滚动不可见区域。 晚上我又改了一下 对xxx_div做了一下修改。 看看能否满足

你的要求

在body的可见区域漂浮!

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>经典的js物理d性漂浮图片广告代码丨芯晴网页特效丨CsrCode.Cn</title>

</head>

<p class="intro_p"><body style="margin:0padding:0">

<div id="xxx_div" style=" left: expression(0)border:0px #ccc solidWIDTH: 100%POSITION: absoluteTOP: expression(body.scrollTop)HEIGHT: 100%left: 0pxtop: 0px"></div>

<div>

<DIV id=img1 style="Z-INDEX: 100LEFT: 2pxWIDTH: 59pxPOSITION: absoluteTOP: 43pxHEIGHT: 61px

visibility: visible"><a href="" target="_blank"><img src="" width="250" height="60" border="0"></a></DIV>

<div align="center">

<p>

<SCRIPT>

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

img1.style.top = yPos

function changePos()

{

var objd = document.getElementById("xxx_div")

//width = document.body.clientWidth

//height = document.body.clientHeight

width = objd.clientWidth

height = objd.clientHeight

Hoffset = img1.offsetHeight

Woffset = img1.offsetWidth

img1.style.left = xPos + objd.offsetLeft

img1.style.top = yPos + objd.offsetTop

if (yon)

else

if (yPos <0)

if (yPos >= (height - Hoffset))

if (xon)

else

if (xPos <0)

if (xPos >= (width - Woffset))

}

function start()

{

img1.visibility = "visible"

interval = setInterval('changePos()', delay)

}

function pause_resume()

{

if(pause)

{

clearInterval(interval)

pause = false}

else

{

interval = setInterval('changePos()',delay)

pause = true

}

}

start()

</SCRIPT>

</p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p>js物理d性漂浮广告</p>

<p></p>

<p></p>

</div>

<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>asdsad

<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>asdasd

</body>

</html>

下面这个是在指定定的小窗口内飘动,我改了一下测试可以运行:

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>经典的js物理d性漂浮图片广告代码丨芯晴网页特效丨CsrCode.Cn</title>

</head>

<p class="intro_p"><body>

<div id="xxx_div" style="top:20pxleft:50pxwidth:600pxheight:500pxborder:2px #ccc solid"></div>

<div>

<DIV id=img1 style="Z-INDEX: 100LEFT: 2pxWIDTH: 59pxPOSITION: absoluteTOP: 43pxHEIGHT: 61px

visibility: visible"><a href="" target="_blank"><img src="" width="250" height="60" border="0"></a></DIV>

<div align="center">

<p>

<SCRIPT>

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

img1.style.top = yPos

function changePos()

{

var objd = document.getElementById("xxx_div")

//width = document.body.clientWidth

//height = document.body.clientHeight

width = objd.clientWidth

height = objd.clientHeight

Hoffset = img1.offsetHeight

Woffset = img1.offsetWidth

img1.style.left = xPos + objd.offsetLeft

img1.style.top = yPos + objd.offsetTop

if (yon)

else

if (yPos <0)

if (yPos >= (height - Hoffset))

if (xon)

else

if (xPos <0)

if (xPos >= (width - Woffset))

}

function start()

{

img1.visibility = "visible"

interval = setInterval('changePos()', delay)

}

function pause_resume()

{

if(pause)

{

clearInterval(interval)

pause = false}

else

{

interval = setInterval('changePos()',delay)

pause = true

}

}

start()

</SCRIPT>

</p>

<p></p>

<p></p>

<p></p>

<p></p>

<p></p>

<p>js物理d性漂浮广告</p>

<p></p>

<p></p>

</div>

</body>

</html>

<div id="img" style="position:absoluteleft:35pxtop:556pxwidth:120height:172">

<a href="/"qyml7.htm"><img border="0" src="/"lo1.gif" width="140" height="120"></a></p>

</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>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/6266425.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-19
下一篇 2023-03-19

发表评论

登录后才能评论

评论列表(0条)

保存