【教程】鼠标经过图片在其上显示一个小图标(二)js写法

效果说明:鼠标经过图1,变成图2样式,IE8下测试通过

                                 图1

                                 图2

下面介绍使用js来写

css代码

#c1 {
	width: 300px;
	height: 250px;
	border: 1px solid #000;
	position: relative;
}
#c1 .img1 {
	width: 300px;
	height: 250px;	
}
#c1 #c1_1 {
	width: 300px;
	height: 56px;
	line-height: 50px;
	text-align: center;
	position: absolute;
	left: 0;
	top: 144px;	
	display: none;
}
#c1 #c1_2 {
	width: 300px;
	height: 50px;
	line-height: 50px;
	text-align: center;
	position: absolute;
	left: 0;
	top: 200px;	
	background: #F00;
}
#c1 #c1_2 a {
	color: #ffffff;
	text-decoration: none;
	font-weight: bold;
}
#c1 #c1_2 a:hover {
	color: #fff;
	text-decoration: underline;	
	font-weight: bold;	
}

html代码

<div id="c1">
	<img src="img02.jpg"  class="img1" onmouseover="showicon()" onmouseout="hideicon()"/>
    <div id="c1_1"><img src="icon01.png"/></div>
	<div id="c1_2"><a href="#">海运服务</a></div>
</div>

js代码

function showicon(){
	document.getElementById("c1_1").style.display="block";
}
function hideicon(){
	document.getElementById("c1_1").style.display="none";
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hifhf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值