文本的浮动效果

floating effect for text

我想对一些文本应用浮动效果。我用选取框试了一下。

.bounce {
  height: 50px;
  overflow: hidden;
  position: relative;
}
.bounce p {
  position: absolute;
  width: 50%;
  margin: 0;
  line-height: 50px;
  text-align: center;
  color: #FFF;
  opacity: 0.7;
  -moz-transform: translateX(50%);
  -webkit-transform: translateX(50%);
  transform: translateX(50%);
  -moz-animation: bouncing-text 25s linear infinite alternate;
  -webkit-animation: bouncing-text 25s linear infinite alternate;
  animation: bouncing-text 25s linear infinite alternate;
}
@keyframes bouncing-text {
  0% {
    -moz-transform: translateX(50%);
    -webkit-transform: translateX(50%);
    transform: translateX(50%);
  }
  100% {
    -moz-transform: translateX(-50%);
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
  }
<div class="bounce">
  <p>SOFT LANDSCAPING</p>
  <br />
  <p>HARD LANDSCAPING</p>
  <br />
</div>

这是为了弹跳。我想让文字像在水中一样漂浮。 请帮我找到解决办法。如果有任何其他方式,请告诉我。

你可以用 hover.css 来完成。您必须使用 :hover 选择器中的代码并将其添加到元素的样式本身以使其工作。

.hvr-bob {
  -webkit-animation-name: hvr-bob-float, hvr-bob;
  animation-name: hvr-bob-float, hvr-bob;
  -webkit-animation-duration: .3s, 1.5s;
  animation-duration: .3s, 1.5s;
  -webkit-animation-delay: 0s, .3s;
  animation-delay: 0s, .3s;
  -webkit-animation-timing-function: ease-out, ease-in-out;
  animation-timing-function: ease-out, ease-in-out;
  -webkit-animation-iteration-count: 1, infinite;
  animation-iteration-count: 1, infinite;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
  -webkit-animation-direction: normal, alternate;
  animation-direction: normal, alternate;
}

勾选JSFiddle。不要忘记添加 hover.css / hover-min.css.

您可以使用 css3 animation-name 属性.

实现此目的

HTML:

<div class="floating">
  Floating effect like water
</div>

CSS :

.floating {
    -webkit-animation-name: Floatingx;
    -webkit-animation-duration: 3s;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: ease-in-out;
    -moz-animation-name: Floating;
    -moz-animation-duration: 3s;
    -moz-animation-iteration-count: infinite;
    -moz-animation-timing-function: ease-in-out;
    margin-left: 30px;
    margin-top: 5px;
}

@-webkit-keyframes Floatingx {
    from {-webkit-transform:translate(0, 0px);}
    65% {-webkit-transform:translate(0, 15px);}
    to {-webkit-transform: translate(0, -0px);}    
}

@-moz-keyframes Floating {
    from {-moz-transform:translate(0, 0px);}
    65% {-moz-transform:translate(0, 15px);}
    to {-moz-transform: translate(0, -0px);}    
}

这里正在工作fiddle

有关动画名称如何工作的更多信息,请查看:animate-name property