亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在懸停時創建橡膠動畫

在懸停時創建橡膠動畫

慕的地6264312 2023-10-30 19:58:24
我正在制作我的網站,希望當您將鼠標懸停在我的標題中的每個字母時都有橡膠效果。一個明顯的例子可以在https://jacekjeznach.com/home部分看到。我考慮過讓每個字母成為一個帶有類的跨度,通過懸停來改變它的大小和顏色。但我不知道如何創建“橡膠”效果,或者如何創建動畫。任何想法?我會很感激。
查看完整描述

1 回答

?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

我已經創建了一個示例,但您需要一點 JavaScript 才能正常工作。此代碼使用默認情況下已包含在 WordPress 中的 jQuery。

如果您不想使用 javaScript,我已經包含了 CSS :hover,您可以取消注釋并刪除 javaScript,但要知道一旦用戶不再將鼠標懸停在元素上,動畫就會停止。

$(".rubberBand").bind("webkitAnimationEnd mozAnimationEnd animationend", function(){

  $(this).removeClass("animated")  

})


$(".rubberBand").hover(function(){

  $(this).addClass("animated");        

})

span.rubberBand {

  display: inline-block;

  animation-duration: 1s;

  animation-fill-mode: both;

  animation-iteration-count: 1;

  font-size: 60px;

  font-weight: bold;

}


span.rubberBand.animated {

  -webkit-animation-name: rubberBand;

  animation-name: rubberBand;

}


/*

WITHOUT JAVASCRIPT, UNCOMMENT THESE LINES AND YOU'LL SEE THAT THE ANIMATION STOPS WHEN YOU HOVER OUT

*/

/*

span.rubberBand:hover {

  -webkit-animation-name: rubberBand;

  animation-name: rubberBand;

}

*/


@keyframes rubberBand {

  from {

    transform: scale3d(1, 1, 1);

  }


  30% {

    transform: scale3d(1.25, 0.75, 1);

  }


  40% {

    transform: scale3d(0.75, 1.25, 1);

  }


  50% {

    transform: scale3d(1.15, 0.85, 1);

  }


  65% {

    transform: scale3d(0.95, 1.05, 1);

  }


  75% {

    transform: scale3d(1.05, 0.95, 1);

  }


  to {

    transform: scale3d(1, 1, 1);

  }

}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<span class="rubberBand">H</span>

<span class="rubberBand">E</span>

<span class="rubberBand">L</span>

<span class="rubberBand">L</span>

<span class="rubberBand">O</span>


查看完整回答
反對 回復 2023-10-30
  • 1 回答
  • 0 關注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號