如何使用js漂浮广告代码,急!!!!!!
我在网上下了一个js漂浮广告代码,单独使用没问题,但放在网页上,图片无法漂浮,被固定在一个地方,无论我放在什么地方都不行,这是怎么回事啊?源代码:<html><head>...
我在网上下了一个js漂浮广告代码,单独使用没问题,但放在网页上,图片无法漂浮,被固定在一个地方,无论我放在什么地方都不行,这是怎么回事啊?
源代码:
<html>
<head>
<title>漂浮广告代码</title>
</head>
<body>
<div id="img4" style="position:absolute;z-index=99;">
<a href="/"><img src="../images/float.png" border="0"></a>
</div>
<script language="javascript" type="text/javascript">
<!-- Begin
var xPos = document.body.clientWidth-20;
var yPos = document.body.clientHeight/2;
var step = 1;
var delay = 5;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
img4.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img4.offsetHeight;
Woffset = img4.offsetWidth;
img4.style.left = xPos + document.body.scrollLeft;
img4.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() {
img4.visibility = "visible";
interval = setInterval('changePos()', delay);
}
start();
img4.onmouseover = function() {
clearInterval(interval);
interval = null;
}
img4.onmouseout = function() {
interval = setInterval('changePos()', delay);
}
// End -->
</script>
</body>
</html>
我在网页中还插入了一个js代码,是不是引起冲突了?
源代码:
<script type="text/javascript">
;(function(){
var i=0;
var $=function(ID){return document.getElementById(ID);};
var timer=null,speed=4000;
$("img").getElementsByTagName("li")[0].style.display="block";
;(function(){
if(i>=$("img").getElementsByTagName("li").length){
for(var j=0;j<$("img").getElementsByTagName("li").length;j++){
$("img").getElementsByTagName("li")[j].style.display="none";
}
i=1;
$("img").getElementsByTagName("li")[0].style.display="block";
} else {
for(var j=0;j<$("img").getElementsByTagName("li").length;j++){
//console.log(j+""+i);
if(j===i){
$("img").getElementsByTagName("li")[j].style.display="block";
} else {
$("img").getElementsByTagName("li")[j].style.display="none";
}
}
i++;
}
timer=setTimeout(arguments.callee,speed);
})();
})();
</script> 展开
源代码:
<html>
<head>
<title>漂浮广告代码</title>
</head>
<body>
<div id="img4" style="position:absolute;z-index=99;">
<a href="/"><img src="../images/float.png" border="0"></a>
</div>
<script language="javascript" type="text/javascript">
<!-- Begin
var xPos = document.body.clientWidth-20;
var yPos = document.body.clientHeight/2;
var step = 1;
var delay = 5;
var height = 0;
var Hoffset = 0;
var Woffset = 0;
var yon = 0;
var xon = 0;
var pause = true;
var interval;
img4.style.top = yPos;
function changePos() {
width = document.body.clientWidth;
height = document.body.clientHeight;
Hoffset = img4.offsetHeight;
Woffset = img4.offsetWidth;
img4.style.left = xPos + document.body.scrollLeft;
img4.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() {
img4.visibility = "visible";
interval = setInterval('changePos()', delay);
}
start();
img4.onmouseover = function() {
clearInterval(interval);
interval = null;
}
img4.onmouseout = function() {
interval = setInterval('changePos()', delay);
}
// End -->
</script>
</body>
</html>
我在网页中还插入了一个js代码,是不是引起冲突了?
源代码:
<script type="text/javascript">
;(function(){
var i=0;
var $=function(ID){return document.getElementById(ID);};
var timer=null,speed=4000;
$("img").getElementsByTagName("li")[0].style.display="block";
;(function(){
if(i>=$("img").getElementsByTagName("li").length){
for(var j=0;j<$("img").getElementsByTagName("li").length;j++){
$("img").getElementsByTagName("li")[j].style.display="none";
}
i=1;
$("img").getElementsByTagName("li")[0].style.display="block";
} else {
for(var j=0;j<$("img").getElementsByTagName("li").length;j++){
//console.log(j+""+i);
if(j===i){
$("img").getElementsByTagName("li")[j].style.display="block";
} else {
$("img").getElementsByTagName("li")[j].style.display="none";
}
}
i++;
}
timer=setTimeout(arguments.callee,speed);
})();
})();
</script> 展开
2个回答
展开全部
你可以用alert输出yPos试试,看得到的值是什么值,有可能是没获得值。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询