一段JS代码的浏览器兼容问题,在线等!!!!
代码在这个网页里面,http://www.daimajiayuan.com/sitejs-8815-1.html。这段代码在safari浏览器里面有效果,在chrome浏...
代码在这个网页里面,http://www.daimajiayuan.com/sitejs-8815-1.html。
这段代码在safari浏览器里面有效果,在chrome浏览器里面却没有任何效果,麻烦高手帮忙看看,有没有什么办法让这段代码兼容chrome浏览器? 展开
这段代码在safari浏览器里面有效果,在chrome浏览器里面却没有任何效果,麻烦高手帮忙看看,有没有什么办法让这段代码兼容chrome浏览器? 展开
2个回答
展开全部
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>JavaScript生成的动态下雨背景效果</TITLE>
</HEAD>
<BODY bgcolor="#fef4d2">
<script>
var rainsize = 40;
var speed = 10;
var x = [];
var y = [];
var r = [];
var cx = [];
var cy = [];
var sn, cs;
var i;
var doc_width = document.documentElement.clientWidth
|| document.body.clientWidth;
var doc_height = document.documentElement.clientHeight
|| document.body.clientHeight;
for (i = 0; i < rainsize; ++i) {
initRain();
if (i == 0) {
document.write("<div id=\"dot" + i + "\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: " + i + "; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><font color=\"blue\">");
document.write(",</font></div>");
} else {
document.write("<div id=\"dot" + i + "\" style=\"POSITION: ");
document.write("absolute; Z-INDEX: " + i + "; VISIBILITY: ");
document.write("visible; TOP: 15px; LEFT: 15px;\"><font color=\"blue\">");
document.write(",.</font></div>");
}
}
function initRain() {
var 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 raindropIE() {
for (i = 0; i < rainsize; ++i) {
updateRain();
if (x[i] <= 1
|| x[i] >= (doc_width - 20)
|| y[i] >= (doc_height - 20)) {
makeRain();
doc_width = document.documentElement.clientWidth
|| document.body.clientWidth;
doc_height = document.documentElement.clientHeight
|| document.body.clientHeight;
}
var dot = document.getElementById("dot" + i);
dot.style.top = y[i] + "px";
dot.style.left = x[i] + "px";
}
setTimeout("raindropIE()", speed);
}
function updateRain() {
r[i] += 10;
x[i] = r[i] * sn + cx[i];
y[i] = r[i] * cs + 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];
}
raindropIE();
</script>
</BODY>
</HTML>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询