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

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

起始頁動畫

起始頁動畫

元芳怎么了 2022-12-22 15:58:22
我正在嘗試在首次加載時為我的主頁創建動畫。我想要我必須從頁面底部升起的球,但是一旦它到達中間,用戶就可以單擊它并擴展到整個頁面。我有這里的升球代碼:*, *::after, *::before {box-sizing: inherit;}html{    box-sizing: border-box;}body{    margin: 0;     padding: 0;    overflow: hidden;}.ball{    background-color: #eb8c28;     width: 100px;    height: 100px;    border-radius: 0%;    position: absolute;    bottom: 0%;    left: 50%;    animation: rise;    animation-duration: 2s;    animation-iteration-count: 1;    animation-fill-mode: forwards;}@keyframes rise{    0%{        border-radius: 50%;    }    100%{        border-radius: 50%;        transform:translateY(-100%);    }    75%{        border-radius: 40%;    }    80%{        border-radius: 30%;    }    90%{        border-radius:20%;    }    100%{        transform: scale(20,20);    }}<!DOCTYPE html><html>    <head>        <link rel="stylesheet" type="text/css" href="ballcopy.css">        <meta name="veiwport" content="width=device-width, initial-scale=1.0">    </head>    <body>        <main>                <div class="ball"></div>        </main>    </body></html>但是,我堅持要如何將球縮放到整個頁面。我應該創建另一個 div 并使其可點擊,還是有辦法創建一個可點擊一半的動畫以使用 JS 完成動畫。
查看完整描述

1 回答

?
翻過高山走不出你

TA貢獻1875條經驗 獲得超3個贊

您可以使用 Javascript 向ball元素添加一個類(例如click),然后設置一個新動畫,以便在設置該類后運行。它基本上將您的原始動畫一分為二。


// Get the ball element

let ball = document.getElementsByClassName("ball");

// First instance of the ball object, add a click listener.

ball[0].addEventListener('click', (event) => {

  // add the click class

  ball[0].classList.add('click');

});

*,

*::after,

*::before {

  box-sizing: inherit;

}


html {

  box-sizing: border-box;

}


body {

  margin: 0;

  padding: 0;

  overflow: hidden;

}


.ball {

  background-color: #eb8c28;

  width: 100px;

  height: 100px;

  border-radius: 0;

  position: absolute;

  bottom: 0%;

  /* Added calc here to center the ball */

  left: calc(50% - 50px);

  animation: rise;

  animation-duration: 2s;

  animation-iteration-count: 1;

  animation-fill-mode: forwards;

}


.ball.click {

  animation: fill;

  animation-duration: 2s;

  animation-iteration-count: 1;

  animation-fill-mode: forwards;

}


@keyframes rise {

  0% {

    border-radius: 50%;

  }

  100% {

    border-radius: 50%;

    transform: translateY(-100%) scale(1);

  }

}


@keyframes fill {

  0% {

    border-radius: 50%;

    transform: translateY(-100%) scale(1);

  }

  100% {

    border-radius: 0;

    transform: translateY(-100%) scale(20);

  }

}

<!DOCTYPE html>

<html>


<head>

  <link rel="stylesheet" type="text/css" href="ballcopy.css">

  <meta name="veiwport" content="width=device-width, initial-scale=1.0">

</head>


<body>

  <main>

    <div class="ball"></div>

  </main>

</body>


</html>


查看完整回答
反對 回復 2022-12-22
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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