悬停时更改链接图像
changing link image on hover
我今天的问题可能有一个简单的答案,但我找到了一些工作示例,但似乎无法将其转移到我的网页上。
我正在尝试使用一个图像作为链接,并希望当你将鼠标悬停在它上面时,图像会发生变化。下面的链接是我试图实现的,但无论出于什么原因,当我将代码从页面替换到它时,它都不起作用。
示例http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_ev_onmouseover
我现在完全迷路了,只需要一点帮助。这是我的密码。
演示
function hoverImg(x) {
x.style.backgroundImage = "url(image/arrowBtnHover.png)"
x.style.transition = "ease 0.5s"
}
function normalImg(x) {
x.style.backgroundImage = "url(image/arrowBtn.png)"
}
#header {
background-color: #473D39;
height: 100%;
width: 100%;
display: table;
position: absolute;
z-index: 10;
}
#wrapper {
display: table-cell;
vertical-align: middle;
}
#header h1 {
text-align: center;
margin: 0px;
font-size: 80px;
padding-top: 5%;
font-weight: normal;
color: #FFF;
letter-spacing: 18px;
text-transform: uppercase;
}
#header h5 {
text-align: center;
color: #FFF;
margin: 15px 15px 50px;
font-weight: normal;
text-transform: uppercase;
font-size: 14px;
letter-spacing: 2px;
}
<div id="header">
<div id="wrapper">
<h1>Premier Webster</h1>
<h5>Local Web Design For The Profesional In You</h5>
<img onmouseover="hoverImg(this)" onmouseout="normalImg(this)" src="image/arrowBtn.png" />
</div>
</div>
请查看https://jsfiddle.net/avzfdc2j/3/
它已经使用css与背景图像和转换完成
div.smile {
background-image: url("http://images.clipartpanda.com/stupidity-clipart-1320682287266972230curius_face.svg.hi.png");
background-size: 60px 60px;
height: 60px;
width: 60px;
cursor: pointer;
}
div.smile:hover {
background-image: url("http://images.clipartpanda.com/straight-face-clipart-black-and-white-smiley-face-hi.png");
transition: ease 0.5s;
}
<a href="http://google.com/"><div class="smile"></div></a>
您应该改为更改src
属性:
function hoverImg(x) {
x.src = "image/arrowBtnHover.png"
x.style.transition = "ease 0.5s"
}
function normalImg(x) {
x.src = "image/arrowBtn.png"
}
但我认为这种过渡不会奏效。
因为它是图像,所以需要更改它的src
属性,而不是CSS。
function hoverImg(x) {
x.src = "image/arrowBtnHover.png"
x.style.transition = "ease 0.5s"
}
function normalImg(x) {
x.src = "image/arrowBtn.png"
}
相关文章:
- 如果显示当前图像,则禁用链接
- Javascript图像链接
- 更改标记.js图像/链接表达式
- 如何使用javascript从文件夹中获取图像并发布直接链接
- 当页面包含指向一个图像的多个链接时,fancyBox会复制缩略图辅助图像
- PNG图像被覆盖,但每个图像都有一个链接可以更改,每次一个-Javascript/jQuery/CSS
- javascript 将 IMG 标签中的图像转换为 标签中的实际链接图像
- 一键在一个窗口中打开两个不同的链接图像
- 如何使用 jquery 调整超链接图像的大小
- 重写:导航链接图像按钮效果
- 切片盒,链接图像
- 悬停时更改链接图像
- 在Javascript中使用href=mailto链接图像
- 鼠标悬停时链接图像
- 链接图像到网页链接
- 超链接图像不显示Chrome扩展
- 基于ALT标签的链接图像
- 在基于活动链接图像的导航中改变背景位置
- 将文本和超链接图像添加到表格单元格
- 如何在此代码片段中定位链接图像而不是链接文本