第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將 Javascript 鼠標(biāo)懸停 css 效果應(yīng)用于具有相同類名的所有元素?

如何將 Javascript 鼠標(biāo)懸停 css 效果應(yīng)用于具有相同類名的所有元素?

白豬掌柜的 2023-05-19 16:01:52
img__text當(dāng)用戶將鼠標(biāo)懸停在 上時(shí),我想將不透明度增加到 1 text__container。text__container我已經(jīng)嘗試通過(guò)嚴(yán)格的 CSS 來(lái)實(shí)現(xiàn)這一點(diǎn),方法是像這樣影響孩子,#text__container ~ .img__text然后應(yīng)用所需的 CSS 效果。索引.html<div class="gallery__container">  <div>    <img class="gallery__img" src="./images/image1.png" alt="">    <div id="text__container">      <span class="img__text">Shake & Shot</span>    </div>  </div>  <div>    <img class="gallery__img" src="./images/image2.png" alt="">    <div id="text__container">      <span class="img__text">It's On</span>    </div>  </div>  <div>    <img class="gallery__img" src="./images/image3.png" alt="">    <div id="text__container">      <span class="img__text">Shake & Shot</span>    </div>  </div>  <div>    <img class="gallery__img" src="./images/image4.png" alt="">    <div id="text__container">      <span class="img__text">Shake & Shot</span>    </div>  </div>  <div>    <img class="gallery__img" src="./images/image5.png" alt="">    <div id="text__container">      <span class="img__text">Shake & Shot</span>    </div>  </div>  <div>    <img class="gallery__img" src="./images/image6.png" alt="">    <div id="text__container">      <span class="img__text">Shake & Shot</span>    </div>  </div></div>風(fēng)格.scss//Gallery  .gallery__container {    margin-top: 5%;    display: flex;    flex-direction: row;    flex-wrap: wrap;    justify-content: space-between;    div {      background-color: #000;      width: 49%;      margin: 0 0 2% 0;      height: 665px;      display: grid;            img {        grid-column: 1;        grid-row: 1;        height: 100%;        width: 100%;        z-index: 1;        align-content: center;        transition: 0.8s ease-out;        opacity: 1;        &:hover {          transition: 0.8s ease-in;          cursor: pointer;          opacity: 0.5;        }      }
查看完整描述

1 回答

?
開(kāi)滿天機(jī)

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超13個(gè)贊

您有多個(gè)具有相同 id 的元素 - 將其更改為一個(gè)類。let如果你想分配事件,你的代碼也需要在循環(huán)中使用。終于不是mouseout了mouseleave。


這行得通。


var imgContainer = document.getElementsByClassName('text__container');

var imgText = document.getElementsByClassName('img__text');


for (let i = 0; i < imgText.length; i++) {

  imgContainer[i].addEventListener('mouseover', function() {

    imgText[i].style.opacity = "1";

    imgText[i].style.transition = "0.8s ease-in";

  });


  imgContainer[i].addEventListener('mouseout', function(){

    imgText[i].style.opacity = "0";

    imgText[i].style.transition = "0.8s ease-out";

  });

}

.gallery__container {

    margin-top: 5%;

    display: flex;

    flex-direction: row;

    flex-wrap: wrap;

    justify-content: space-between;

    div {

      background-color: #000;

      width: 49%;

      margin: 0 0 2% 0;

      height: 665px;

      display: grid;

      

      img {

        grid-column: 1;

        grid-row: 1;

        height: 100%;

        width: 100%;

        z-index: 1;

        align-content: center;

        transition: 0.8s ease-out;

        opacity: 1;

        &:hover {

          transition: 0.8s ease-in;

          cursor: pointer;

          opacity: 0.5;

        }

      }

      .text__container {

        border: 1px solid red;

        text-align: center;

        align-self: center;

        grid-column: 1;

        grid-row: 1;

        background-color: rgba(0,0,0,0.5);

        width: 100%;

        height: 100%;

        margin: 0;

        z-index: 2;

        background-color: transparent;

        transition: 0.8s ease-out;

        &:hover {

          transition: 0.8s ease-in;

          background-color: rgba(0,0,0,0.5);

        }

        .img__text {

          border: 1px solid red;

          text-align: center;

          align-self: center;

          z-index: 3;

          color: #fff;

          font-family: $main-font;

          font-size: 2rem;

          width: 50%;

          margin: 0 auto;

          transition: 0.8s ease-out;

          opacity: 0;

        }

      }

    }

  }

<div class="gallery__container">

    <div>

      <img class="gallery__img" src="https://via.placeholder.com/100" alt="">

      <div class="text__container">

        <span class="img__text">Shake & Shot</span>

      </div>

    </div>

    <div>

      <img class="gallery__img" src="https://via.placeholder.com/100" alt="">

      <div class="text__container">

        <span class="img__text">It's On</span>

      </div>

    </div>

    <div>

      <img class="gallery__img" src="https://via.placeholder.com/100" alt="">

      <div class="text__container">

        <span class="img__text">It's On</span>

      </div>

    </div>

    <div>

      <img class="gallery__img" src="https://via.placeholder.com/100" alt="">

      <div class="text__container">

        <span class="img__text">It's On</span>

      </div>

    </div>

  </div>


查看完整回答
反對(duì) 回復(fù) 2023-05-19
  • 1 回答
  • 0 關(guān)注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)