如何在悬停时更改图像和文本

How to change image and text on hover

我正在尝试更改鼠标悬停时的图像和文本,我已经 this in codepen 但它似乎不起作用?

$(".service_1").hover(function() {
  $(".hello").hide();

  $(".text").append("<span class='go'>Appended text</span>");
});
.service_item img {
  position: absolute;
}

.service_item {
  height: 307px;
  width: 700px;
  background-size: cover;
  transition: background-image 0.5s linear;
  -webkit-transition: background-image 0.5s linear;
  float: left;
  position: relative;
}

.service_item:hover {
  transition: background-image 0.5s linear;
  -webkit-transition: background-image 0.5s linear;
}

.serviceimg {
  margin-top: 66px;
  height: 949px;
}

.service_item a {
  height: 50%;
  display: block;
  text-align: center;
  font-size: 30px;
  color: #fff;
  text-transform: uppercase;
  position: relative;
}

.service_item img {
  position: absolute;
  left: 0px;
  width: 100%;
  height: 300px;
  transition: opacity .5s ease;
}

.service_item img:hover {
  opacity: 0;
}

.service_item span {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="service_item service_1">
  <a href="/uk-marriage-spouse-civil-partner-visa/">
    <img src="http://www.edwards-immigration.co.uk/wp-content/uploads/2017/02/mikhail-pavstyuk-8436.png">
    <img src="http://www.edwards-immigration.co.uk/wp-content/uploads/2017/02/Untitled-1.png">
    <div class="text"><span class="hello">Hello there</span></div>
  </a>
</div>

有人可以指出我哪里出错了吗?

<a href="#">
<img src="http://www.dummy.com/icons/fasticon/angry-birds/128/yellow-bird-icon.png" 
onmouseover="this.src='http://www.dummy.com/icons/fasticon/angry-birds/128/red-bird-icon.png'"
onmouseout="this.src='http://www.dummy.com/icons/fasticon/angry-birds/128/yellow-bird-icon.png'"
border="0" alt=""/></a>

Css 可以处理您想要实现的目标。这是一个使用 css transitionsflex-box 对齐文本的工作示例:

.service_item img {
  position: absolute;
  z-index: -1;
}

.service_item {
  height: 307px;
  width: 700px;
  float: left;
  position: relative;
}

.serviceimg {
  margin-top: 66px;
  height: 949px;
}

.service_item a {
  height: 307px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  font-size: 30px;
  color: #fff;
  text-transform: uppercase;
}

.service_item img {
  position: absolute;
  left: 0px;
  width: 100%;
  height: 300px;
  transition: opacity .5s ease;
}

.service_item:hover img:last-of-type {
  opacity: 0;
}

.service_item:hover .append-text {
  opacity: 1;
}

.append-text {
  opacity: 0;
}
<div class="service_item service_1">
  <a href="/uk-marriage-spouse-civil-partner-visa/">
    <img src="http://www.edwards-immigration.co.uk/wp-content/uploads/2017/02/mikhail-pavstyuk-8436.png">
    <img src="http://www.edwards-immigration.co.uk/wp-content/uploads/2017/02/Untitled-1.png">
    <div class="hello">Hello there</div>
    <div class="append-text">APPENDED TEXT</div>
  </a>
</div>