我想在漂浮广告上实现鼠标经过图片显示详细信息的一个层,漂浮分左右,左边可以实现。但是右边我实现不了
求高手解答,代码如下:<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org...
求高手解答,代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.datu
{
overflow: hidden;
border: 5px solid #ccc;
position: absolute;
display: none;
}
.box2
{
position: absolute;
width: 117px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="box1" id="box1" style="top: 30px; left: 10px;">
<div id="xiaotu">
<div class="tu1">
<img src="xiaotu.jpg" width="80" height="70" /></div>
<div class="wwz">
<a href="#">详情</a></div>
</div>
<div class="datu" id="xiangxi">
<img src="datu.jpg" width="280" height="170" />
</div>
<script type='text/javascript'>
var demo = document.getElementById("xiaotu");
var gg = demo.getElementsByTagName("img");
var ei = document.getElementById("xiangxi");
for (i = 0; i < gg.length; i++) {
var ts = gg[i];
ts.onmousemove = function(event) {
event = event || window.event;
ei.style.display = "block";
ei.style.top = document.body.scrollTop + event.clientY + 10 + "px";
ei.style.left = document.body.scrollLeft + event.clientX + 10 + "px";
}
ts.onmouseout = function() {
ei.style.display = "none";
}
ts.onclick = function() {
window.open(this.src);
}
}
</script>
</div>
<div class="box2" id="box2" style="top: 30px; right: 10px;">
<div id="Div1">
<img src="xiaotu.jpg" width="80" height="70" /></div>
</div>
<script type="text/javascript">
var id = function(o) { return document.getElementById(o) }
var scroll = function(o) {
var space = id(o).offsetTop;
id(o).style.top = space + 'px';
void function() {
var goTo = 0;
var roll = setInterval(function() {
var height = document.documentElement.scrollTop + document.body.scrollTop + space;
var top = parseInt(id(o).style.top);
if (height != top) {
goTo = height - parseInt((height - top) * 0.9);
id(o).style.top = goTo + 'px';
}
//else{if(roll) clearInterval(roll);}
}, 10);
} ()
}
scroll('box1');
scroll('box2');
</script>
</form>
</body>
</html> 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.datu
{
overflow: hidden;
border: 5px solid #ccc;
position: absolute;
display: none;
}
.box2
{
position: absolute;
width: 117px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="box1" id="box1" style="top: 30px; left: 10px;">
<div id="xiaotu">
<div class="tu1">
<img src="xiaotu.jpg" width="80" height="70" /></div>
<div class="wwz">
<a href="#">详情</a></div>
</div>
<div class="datu" id="xiangxi">
<img src="datu.jpg" width="280" height="170" />
</div>
<script type='text/javascript'>
var demo = document.getElementById("xiaotu");
var gg = demo.getElementsByTagName("img");
var ei = document.getElementById("xiangxi");
for (i = 0; i < gg.length; i++) {
var ts = gg[i];
ts.onmousemove = function(event) {
event = event || window.event;
ei.style.display = "block";
ei.style.top = document.body.scrollTop + event.clientY + 10 + "px";
ei.style.left = document.body.scrollLeft + event.clientX + 10 + "px";
}
ts.onmouseout = function() {
ei.style.display = "none";
}
ts.onclick = function() {
window.open(this.src);
}
}
</script>
</div>
<div class="box2" id="box2" style="top: 30px; right: 10px;">
<div id="Div1">
<img src="xiaotu.jpg" width="80" height="70" /></div>
</div>
<script type="text/javascript">
var id = function(o) { return document.getElementById(o) }
var scroll = function(o) {
var space = id(o).offsetTop;
id(o).style.top = space + 'px';
void function() {
var goTo = 0;
var roll = setInterval(function() {
var height = document.documentElement.scrollTop + document.body.scrollTop + space;
var top = parseInt(id(o).style.top);
if (height != top) {
goTo = height - parseInt((height - top) * 0.9);
id(o).style.top = goTo + 'px';
}
//else{if(roll) clearInterval(roll);}
}, 10);
} ()
}
scroll('box1');
scroll('box2');
</script>
</form>
</body>
</html> 展开
1个回答
展开全部
左边那段代码是OK的,
而右边 var id = function(o) { return document.getElementById(o) }--------这里面是获取id=o;
而你根本没有定义id,那怎么能获取呢
如果你要求两边的效果是一样的话,建议右边套用左边的代码(所有的id换一下),保留
<div class="box2" id="box2" style="top: 30px; right: 10px;">
就可以了
而右边 var id = function(o) { return document.getElementById(o) }--------这里面是获取id=o;
而你根本没有定义id,那怎么能获取呢
如果你要求两边的效果是一样的话,建议右边套用左边的代码(所有的id换一下),保留
<div class="box2" id="box2" style="top: 30px; right: 10px;">
就可以了
追问
右边的和左边一样调用哪个JS的话 是不行的,我试过了 而且提问这里写不了太多代码我删除了一部分写上来的 ,你把右边的套进去用用看怎么修改会可以?
追答
这里以下替换下就ok了,你运行下看看是不是你要的效果?
希望能帮到你
详情
var demo2 = document.getElementById("xiaotu2");
var gg2 = demo2.getElementsByTagName("img");
var ei2 = document.getElementById("xiangxi2");
for (i = 0; i
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询