Ste*_*eve 11 javascript css onclick hover mouseevent
我有一个我想实现的身体系统功能.当用户将鼠标悬停在身体部位上时,它会突出显示该特定身体部位的信息.我已经按照我想要的方式对CSS进行了编码,但是当我点击正文部分或鼠标离开悬停状态时,我对JavaScript没有任何了解.
我搜索了论坛,发现了类似的问题,花了好几个小时试图从别人的javascript解决方案中解决这个问题 - 我正处于需要求助的地步.
这是我用我想要的效果制作的flash原型:
http://inwavemedia.com/temp/proto/Main.html
如果您想查看我现在拥有的内容,这是实时HTML:
http://inwavemedia.com/temp/excretory.html
这是我的代码:
<style type="text/css">
#bodysystem-excretory {
width: 618px;
height: 504px;
background: url(excretory.png) no-repeat;
margin: 10px auto; padding: 0;
position: relative;
border: 1px solid #999;
}
#bodysystem-excretory li {
margin: 0;
padding: 0;
list-style: none;
display: block;
position: absolute;
}
#bodysystem-excretory a {
display: block;
/* text-indent: -9999px;*/
text-decoration: none;
}
#esoph {
left: 85px;
top: 41px;
width: 46px;
height: 94px;
z-index: 10;
}
#lungs {
left: 76px;
top: 84px;
width: 84px;
height: 68px;
z-index: 20;
}
#bladder {
left: 87px;
top: 148px;
width: 64px;
height: 104px;
z-index: 30;
}
#esoph a {
height: 94px;
}
#lungs a {
height: 67px;
}
#bladder a {
height: 104px;
}
#esoph a:hover {
background-image: url(excretory.png);
background-repeat: no-repeat;
background-position: -25px -561px;
}
#lungs a:hover {
background-image: url(excretory.png);
background-repeat: no-repeat;
background-position: -105px -523px;
}
#bladder a:hover {
background-image: url(excretory.png);
background-repeat: no-repeat;
background-position: -114px -618px;
}
.info span{
display: none
}
.info{
position:relative;
z-index:1124;
color:#000;
}
.info:hover{
z-index:1125;
}
.info:hover span{
display:block;
position:absolute;
top:-30px;
left:155px;
width:370px;
color:#000;
background-color:#FFFFFF;
}
</style>
</head>
<body>
<ul id="bodysystem-excretory">
<li id="esoph">
<a href="#" class="info"><span id="esoph-info"><h3>Esophagus</h3><p>This is esophagus information. This is esophagus information. This is esophagus information. This is esophagus information. This is esophagus information. This is esophagus information. This is esophagus information. </p></span></a>
</li>
<li id="lungs"><a href="#" class="info"><span id="lungs-info"><h3>Lungs</h3></span></a></li>
<li id="bladder"><a href="#" class="info"><span id="bladder-info"><h3>Bladder</h3></span></a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
您可以添加一个单击事件,该事件查看我们单击的内容,然后在单击时永久更改样式。这将永久地“显示”新部件。
您的 HTML:
<li id="lungs" onclick="highlight(this.id)">
<!--some stuff-->
</li>
Run Code Online (Sandbox Code Playgroud)
在 javascript 中(为了简单起见,我将其放入<script>标签中,只需将此 + 您的其他情况添加到标题中的某处即可):
<script>
function highlight(id) {
var part = document.getElementById(id);
switch(id){
case "lungs":
part.style.backgroundImage="url(excretory.png)";
part.style.backgroundRepeat="no-repeat";
part.style.backgroundPosition="-105px 523px";
break;
//rinse repeat for all cases, don't forget the : after your case and to add break; at the end of each line
default:
//do nothing, or something, whatever
}
</script>
Run Code Online (Sandbox Code Playgroud)
您可以在此处了解有关 javascript switch 语句的更多信息。
| 归档时间: |
|
| 查看次数: |
5192 次 |
| 最近记录: |