亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.430618.com 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線(xiàn)咨詢(xún)客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

在本教程中,我們將學(xué)習(xí)使用 HTML 和 CSS 在用戶(hù)懸停時(shí)搖動(dòng)按鈕。創(chuàng)建搖動(dòng)按鈕可以使應(yīng)用程序的用戶(hù)體驗(yàn)更具吸引力。

我們需要使用 CSS“關(guān)鍵幀”規(guī)則創(chuàng)建自定義動(dòng)畫(huà)來(lái)?yè)u動(dòng)任何 HTML 元素。之后,我們可以使用自定義關(guān)鍵幀作為“animation”CSS屬性的值,以便當(dāng)用戶(hù)將鼠標(biāo)懸停在按鈕上時(shí)搖動(dòng)按鈕。

語(yǔ)法

用戶(hù)可以按照以下語(yǔ)法使用 HTML 和 CSS 來(lái)?yè)u動(dòng)懸停按鈕。

.btn:hover {
   animation: key_frame_name animation_time repetition;
}
@keyframes key_frame_name {
   0% {
      transform: rotate(0deg);
   }
   100% {
      transform: rotate(10deg);
   }
}

登錄后復(fù)制

在上面的語(yǔ)法中,我們創(chuàng)建了自定義 CSS 規(guī)則來(lái)向按鈕添加晃動(dòng)動(dòng)畫(huà)。用戶(hù)可以將“animation_time”替換為時(shí)間單位,并將“repetition”替換為數(shù)字來(lái)重復(fù)動(dòng)畫(huà)。

Example

的中文翻譯為:

示例

在下面的示例中,我們垂直搖動(dòng)按鈕。我們使用“button”標(biāo)簽創(chuàng)建了普通的 HTML 按鈕,并給出了“btn”類(lèi)名稱(chēng)。我們使用類(lèi)名訪(fǎng)問(wèn)該按鈕并設(shè)置其樣式。

在 CSS 中,我們使用“animation”屬性在用戶(hù)懸停按鈕時(shí)向按鈕添加“晃動(dòng)”關(guān)鍵幀。在“搖動(dòng)”關(guān)鍵幀中,我們?cè)?0% 的動(dòng)畫(huà)時(shí)間將按鈕旋轉(zhuǎn)“0 度”,在 20% 的時(shí)間旋轉(zhuǎn)“5 度”,在 50% 的時(shí)間旋轉(zhuǎn)按鈕“0 度”,在 50% 的時(shí)間旋轉(zhuǎn)按鈕“5 度” 70% 的時(shí)間為“0 度”,100% 的時(shí)間為“0 度”。

在輸出中,用戶(hù)可以觀察到按鈕在垂直方向上的晃動(dòng)。

<html>
   <style>
      .btn {
         justify-content: center;
         align-items: center;
         height: fit-content;
         padding: 10px 20px;
         border: 1px solid #000;
         border-radius: 5px;
         background-color: red;
         color: white;
         font-size: 40px;
      }
      .btn:hover {animation: shaking 0.5s infinite;}
      @keyframes shaking {
         0% {transform: rotate(0deg);}
         20% {transform: rotate(-4deg);}
         50% {transform: rotate(0deg);}
         70% {transform: rotate(4deg);}
         100% {transform: rotate(0deg);}
      }
   </style>
   <body>
      <h2> Shaking the button vertically using HTML and CSS </h2>
      <p> Please hover the cursor over the button below to see the shaking effect.</p>
      <div>
         <button class = "btn"> Submit </button>
      </div>
   </body>
</html>

登錄后復(fù)制

Example

的中文翻譯為:

示例

在下面的示例中,我們使用HTML和CSS水平晃動(dòng)按鈕。

我們使用了CSS屬性 ‘transform: translateX()’ 來(lái)在水平方向上抖動(dòng)按鈕。首先,我們將按鈕向負(fù)方向移動(dòng)。接下來(lái),我們將按鈕移動(dòng)到原始位置。然后,我們將按鈕向正方向移動(dòng),最后,我們使用CSS的 ‘keyframes’ 規(guī)則將按鈕移動(dòng)到原始位置

<html>
   <style>
      .btn {
         justify-content: center;
         align-items: center;
         height: fit-content;
         padding: 10px 20px;
         border: 1px solid #000;
         border-radius: 5px;
         background-color: black;
         color: white;
         font-size: 40px;
      }
      .btn:hover {animation: shaking 0.4s infinite;}
      @keyframes shaking {
         0% {transform: translateX(-10px);}
         20% {transform: translateX(-5px);}
         50% {transform: translateX(-5px);}
         70% {transform: translateX(-5px);}
         80% {transform: translateX(10px);}
         90% {transform: translateX(-10px);}
      }
   </style>
   <body>
      <h2> Shaking the button Horizontally using HTML and CSS </h2>
      <p> Please hover the cursor over the button below to see the shaking effect.</p>
      <div>
         <button class = "btn"> Hover the Button </button>
      </div>
   </body>
</html>

登錄后復(fù)制

Example

的中文翻譯為:

示例

在下面的示例中,我們將學(xué)習(xí)如何水平和垂直地?fù)u晃按鈕。我們使用‘translateX()’和‘rotate()’一起作為‘transform’ CSS屬性的值。

‘translateX()’將按鈕水平移動(dòng),‘rotate()’函數(shù)將按鈕垂直移動(dòng)。在輸出中,用戶(hù)可以觀察到當(dāng)他們懸停在按鈕上時(shí),它會(huì)稍微水平和垂直移動(dòng)。然而,用戶(hù)可以增加‘translateX()’函數(shù)的參數(shù)值,以在水平方向上抖動(dòng)更多。

<html>
   <style>
      .btn {
         justify-content: center;
         align-items: center;
         height: fit-content;
         padding: 10px 20px;
         border: 1px solid #000;
         border-radius: 5px;
         background-color: green;
         color: white;
         font-size: 25px;
      }
      .btn:hover {animation: shaking 0.4s infinite;}
      @keyframes shaking {
         0% {transform: translateX(0) rotate(0deg);}
         25% {transform: translateX(15px) rotate(5deg);}
         50% {transform: translateX(0px) rotate(0deg);}
         75% {transform: translateX(-15px) rotate(-5deg);}
         100% {transform: translateX(0px) rotate(0deg);}
      }
   </style>
   <body>
   <h3> Shaking the button Horizontally and vartically using HTML and CSS</h3>
   <div>
      <button class = "btn"> Point out the Button </button>
   </div>
</body>
</html>

登錄后復(fù)制

結(jié)論

在本教程中,用戶(hù)學(xué)會(huì)了只使用CSS來(lái)抖動(dòng)HTML按鈕。在第一個(gè)示例中,我們學(xué)會(huì)了垂直抖動(dòng)按鈕。在第二個(gè)示例中,我們學(xué)會(huì)了水平抖動(dòng)按鈕;在最后一個(gè)示例中,我們學(xué)會(huì)了水平和垂直方向上抖動(dòng)按鈕。

以上就是使用HTML和CSS在懸停時(shí)抖動(dòng)按鈕的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!

分享到:
標(biāo)簽:CSS html 懸停 抖動(dòng) 按鈕
用戶(hù)無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過(guò)答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定