{welcome to JS} 处理图像(翻转器)

本文介绍了一种使用 HTML 和 JavaScript 实现的简单图片翻转效果。通过改变图像源,在鼠标悬停时显示不同的图像,从而实现交互式的视觉变化。此外,还探讨了这种方法的局限性,并提供了一个不依赖 CSS 文件的替代方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.html

<!DOCTYPE html>
<html>
<head>
   <title>A Simple Rollover</title>
   <link rel="stylesheet" href="script1.css">
</head>
<body>
   <a href="next.html" onmouseover="document.images['arrow'].src='images/arrow_on.gif'" onmouseout="document.images['arrow'].src='images/arrow_off.gif'"><img src="images/arrow_off.gif" id="arrow" alt="arrow"></a>
</body>
</html>


script1.css

body{
	background-color: #FFF;
}
img{
	border-width: 0; 
}
img#arrow,imag#arrowImg{
	width:147px;
	height: 82px;
}
#button1,#button2{
	width: 113px;
	height: 33px;
}
.centered{
	text-align: center;
}
#adBanner{
	width: 400px;
	height: 75px;
}


images文件夹


运行结果



学习心得

onmouseover=“document.images['arrow'].src='images/arrow_on.gif' "
当鼠标移到图像上时(id为arrow的src),images目录中的替换图像arrow_on.gif被写到文档中

onmouseout="document.images['arrow'].src='images/arrow_off.gif'"
当鼠标移走时,arrow_off.gif重新显示


这种翻转器替换图片有延迟 虽然简单并不是很好的方法

当然我也试了一下 不用css文件也同样可行







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值