js鼠标移动至图片上,出现文字鼠标移开文字隐藏代码
2个回答
展开全部
直接利用css就能办到鼠标移上去显示 离开隐藏的效果:
<style>
#aa{position:relative;width:300px; height:200px;}
#aa img{display:block;width:100%;height:100%;}
#aa span{display:none;}
#aa:hover span{position:absolute;left:0;bottom:0;display:block;width:100%;height:30px; line-height:30px;text-align:center; color:#eee;}
</style>
JS写法:
<script>
window.onload = function(){
var box = document.getElementById('aa');
box.onmouseover = function(){
this.getElementsByTagName('span')[0].style.display = 'block';
}
box.onmouseout = function(){
this.getElementsByTagName('span')[0].style.display = 'none';
}
}
</script>
<div id="aa">
<img src="http://pic31.nipic.com/20130725/5252423_162905249000_2.jpg" />
<span>文字内容</span>
</div>
<style>
#aa{position:relative;width:300px; height:200px;}
#aa img{display:block;width:100%;height:100%;}
#aa span{display:none;}
#aa:hover span{position:absolute;left:0;bottom:0;display:block;width:100%;height:30px; line-height:30px;text-align:center; color:#eee;}
</style>
JS写法:
<script>
window.onload = function(){
var box = document.getElementById('aa');
box.onmouseover = function(){
this.getElementsByTagName('span')[0].style.display = 'block';
}
box.onmouseout = function(){
this.getElementsByTagName('span')[0].style.display = 'none';
}
}
</script>
<div id="aa">
<img src="http://pic31.nipic.com/20130725/5252423_162905249000_2.jpg" />
<span>文字内容</span>
</div>
追问
谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询