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

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

如何迭代 HTML <div> 元素數(shù)組并為每個索引號設(shè)置不同樣式的另一個元素?

如何迭代 HTML <div> 元素數(shù)組并為每個索引號設(shè)置不同樣式的另一個元素?

冉冉說 2023-05-19 14:43:53
我希望contentadiv的偽元素的值::after隨著 6 個子元素的索引號而改變div,將鼠標懸停在這 6 個 div 中的每一個上。我堅持創(chuàng)建 6 個 div 的第一個數(shù)組和另一個包含 6 個信息的數(shù)組以顯示相同的對應(yīng)索引號。數(shù)組 #1 將是 [.hov-sq:nth-child(1), .hov-sq:..] 并且數(shù)組 #2 將是每次懸停時更改的 'data-content' 屬性的內(nèi)容 ['digital游牧民族','數(shù)字開發(fā)者','超人','等等...]到目前為止,我設(shè)法使用這個 jQuery 代碼和 CSS 代碼更改了偽元素內(nèi)容。$('.hov-sq').hover(function() {? $('.c-1').attr('data-content', 'frontend developer');});.landing-hov-s {? width: 100vw;? height: 100vh;? position: absolute;? top: 0;? left: 0;? right: 0;? bottom: 0;? display: flex;? flex-wrap: wrap;}.hov-sq {? width: 33.3333333vw;? height: 50vh;? z-index: 5000;}.c-1::after {? /* other styling not relevant to issue */? content: attr(data-content) '';}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div class="landing-hov-s">? <div class="hov-sq"></div>? <div class="hov-sq"></div>? <div class="hov-sq"></div>? <div class="hov-sq"></div>? <div class="hov-sq"></div>? <div class="hov-sq"></div></div><div class="c-1">? <h1>Laurent<br>&nbsp;&nbsp;&nbsp;Chevrette</h1></div>
查看完整描述

2 回答

?
ibeautiful

TA貢獻1993條經(jīng)驗 獲得超6個贊

使用index()確定集合中哪個元素的索引被懸停

const content = ['Item 1','Item 2','Item 3','Item 4','Item 5','Item 6'];


const $sq = $('.hov-sq').hover(function() {

? const idx = $sq.index(this);

? $('.c-1').attr('data-content', content[idx]);

}, function(){

? ?// remove when mouse leaves if wanted?

? ?$('.c-1').attr('data-content','')

});

.landing-hov-s {

? width: 100vw;

? height: 100vh;

? position: absolute;

? top: 0;

? left: 0;

? right: 0;

? bottom: 0;

? display: flex;

? flex-wrap: wrap;

}


.hov-sq {

? width: 33.3333333vw;

? height: 50vh;

? z-index: 5000;

}


.c-1::after {

? /* other styling not relevant to issue */

? content: attr(data-content) '';

}

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

<div class="landing-hov-s">

? <div class="hov-sq">One</div>

? <div class="hov-sq">Two</div>

? <div class="hov-sq">Three</div>

? <div class="hov-sq">Four</div>

? <div class="hov-sq">Five</div>

? <div class="hov-sq">Six</div>

</div>

<div class="c-1">

? <h1>Laurent<br>&nbsp;&nbsp;&nbsp;Chevrette</h1>

</div>



查看完整回答
反對 回復(fù) 2023-05-19
?
寶慕林4294392

TA貢獻2021條經(jīng)驗 獲得超8個贊

jQuery 的索引方法

如果您使用的是 jQuery,則可以訪問該index()方法。

out我還添加了一旦鼠標位于懸停的 div 上就會運行的函數(shù)。

也就是說,請注意您不能選擇偽元素和 Javascript,因此您應(yīng)該使用 CSS 中的屬性選擇器來設(shè)置它們的樣式,如下所示。

$('.hov-sq').hover(function() {

? $('.c-1')

? ? .attr('data-content', 'frontend developer')

? ? .attr('data-index', $(this).index());

? console.log($(this).index())

}, function() {

? $('.c-1')

? ? .attr('data-content', '')

? ? .attr('data-index', '');

});

.landing-hov-s {

? width: 100vw;

? height: 100vh;

? position: absolute;

? top: 0;

? left: 0;

? right: 0;

? bottom: 0;

? display: flex;

? flex-wrap: wrap;

}


.hov-sq {

? width: 33.3333333vw;

? height: 50vh;

? z-index: 5000;

}


.c-1::after {

? /* other styling not relevant to issue */

? content: attr(data-content) '';

}


.c-1[data-index="0"]::after {

? /* Style for index 0 */

}



/* Rest of the styles */

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

<div class="landing-hov-s">

? <div class="hov-sq"></div>

? <div class="hov-sq"></div>

? <div class="hov-sq"></div>

? <div class="hov-sq"></div>

? <div class="hov-sq"></div>

? <div class="hov-sq"></div>

</div>


<div class="c-1">

? <h1>Laurent<br>&nbsp;&nbsp;&nbsp;Chevrette</h1>

</div>


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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