知道如何将这种下沉的悬停效果添加到图像/链接吗?

时间:2016-06-03 22:38:21

标签: html css

Arrow(custom icon) I am trying to animate

我创建了箭头的图标图像,这也是一个链接。它位于背景图像之上。当鼠标悬停在箭头上方时,我想创建一个" sink" 效果,类似于在2d过渡部分here中找到的效果。怎么办呢?

我的CSS / HTML到目前为止:



body {
  padding: 0;
  margin: 0;
}
header {
  height: 100vh;
}
.content {
  height: 150vh;
}
img#bg {
  z-index: -100;
  /* Set rules to fill background */
  min-height: 100%;
  min-width: 1024px;
  /* Set up proportionate scaling */
  width: 100%;
  height: 100%;
  /* Set up positioning */
  position: relative;
  top: 0;
  left: 0;
}
img#arrow {
  position: absolute;
  bottom: 50;
  left: 45.5%;
}
h1#title {
  font-size: 20px;
  font-family: arial;
  margin-top: 2.5em;
  text-align: center;
  color: yellow;
}

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css">
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <title>Tinker Time</title>
</head>

<body>
  <header>
    <img src="assets/building2.jpg" id="bg" alt="" />
    <a href="#anchor">
      <img src="assets/arrow.png" id="arrow" alt="" />
    </a>
  </header>

  <div class="content">
    <a name="anchor"></a>
    <h1>Team Members, About us, Blog</h1>
  </div>
</body>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:1)

如果您使用的是hover.css,这应该可以完成。

只需将hover.css样式表导入HTML

即可
<link rel="stylesheet" type="text/css" href="css/hover.css">

并添加:

<img src="assets/arrow.png" id="arrow" alt="" class="hvr-sink" />

答案 1 :(得分:1)

这个lib的部分悬停代码应该仍然适用于图像,这是一个带有随机头像图标的工作示例:

&#13;
&#13;
/* Sink */
.hvr-sink {
  display: inline-block;
  vertical-align: middle;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -moz-osx-font-smoothing: grayscale;
  -webkit-transition-duration: 0.3s;
  transition-duration: 0.3s;
  -webkit-transition-property: transform;
  transition-property: transform;
  -webkit-transition-timing-function: ease-out;
  transition-timing-function: ease-out;
}
.hvr-sink:hover, .hvr-sink:focus, .hvr-sink:active {
  -webkit-transform: translateY(8px);
  transform: translateY(8px);
&#13;
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<img class="hvr-sink" src="https://www.gravatar.com/avatar/6fce102dc34236cd4e485c69d7293ee9?s=32&d=identicon&r=PG"></img>
<br>

</body>
</html>
&#13;
&#13;
&#13;

答案 2 :(得分:1)

看看这个非常简单的版本 - 如果你愿意,可以是一个图像。

如果您想要的话,那就不需要包括一个歌舞图书馆了!

&#13;
&#13;
.red_box {
  display: block;
  width: 100px;
  height: 100px;
  background: red;
  transition: all 0.5s ease;
}
.red_box:hover {
  transform: translateY(16px);
}
&#13;
<div class="red_box"></div>
&#13;
&#13;
&#13;

答案 3 :(得分:1)

简单:

  1. 将hover.css添加到您的html文件
  2. 将hvr-sink类添加到箭头图像中。
  3. 例如:

        <body>
        <header>
        <img src="assets/building2.png" id="bg" alt="" />
        <a href="#anchor">
          <img src="assets/arrow.png" class="hvr-sink" id="arrow" alt="" />
        </a>
      </header>
      <div class="content">
           <a name="anchor"></a>
            <h1>Team Members, About us, Blog</h1>
          </div>
       </body>
    

    但是,无论如何, stackoverflow 不是代码编写服务。记住这一点!