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

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

將鼠標(biāo)懸停在該元素上時(shí)如何不斷觸發(fā)事件?

將鼠標(biāo)懸停在該元素上時(shí)如何不斷觸發(fā)事件?

慕田峪7331174 2022-10-27 16:29:33
所以,我有一個(gè)按鈕,我想在按鈕懸停時(shí)不斷觸發(fā)一個(gè)事件。如果我使用mouseover,則當(dāng)光標(biāo)從外部某處出現(xiàn)時(shí),此事件僅觸發(fā)一次。btn.addEventListener("mouseover", function(){    console.log("Hello");});例如,我希望此控制臺(tái)日志在光標(biāo)位于按鈕上方時(shí)不斷發(fā)生。
查看完整描述

3 回答

?
暮色呼如

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

請(qǐng)檢查mousemove活動(dòng)是否適合您。


let interval = null;

btn.addEventListener("mousemove", function(){

    console.log("Hello");

});


btn.addEventListener('mouseenter', function(){

  interval= setInterval(()=>console.log('Hello'), 100)

})


btn.addEventListener('mouseout', function(){

 clearInterval(interval)

})

#btn{

    width: 300px;

    height: 60px;

    border-radius: 8px;

}

    <button  id="btn">

    hover me

    </button>


查看完整回答
反對(duì) 回復(fù) 2022-10-27
?
眼眸繁星

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

您可以通過使用mouseoverand mouseout(和 a setInterval)來做到這一點(diǎn)?;旧希髽?biāo)進(jìn)入時(shí)開始一個(gè)間隔,退出時(shí)清除它。


let interval;


btn.addEventListener("mouseover", function(){

    interval = setInterval(function() {

        console.log("Hello");

    }, 100);

});


btn.addEventListener("mouseout", function(){

    clearInterval(interval);

});


查看完整回答
反對(duì) 回復(fù) 2022-10-27
?
隔江千里

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

您可以使用以下組合

  • 標(biāo)志,可以在元素本身上,也可以作為單獨(dú)的變量

  • 一個(gè) setInterval 函數(shù)

找出在任何給定時(shí)間懸停的元素。(這顯然是一個(gè)有點(diǎn)愚蠢的例子,因?yàn)槟悴荒芎芎玫貙⑹髽?biāo)懸停在一次相鄰的多個(gè)元素上。)

function addEventListeners(button) {

  button.addEventListener("mouseover", () => button.dataset.hovered = "1");

  button.addEventListener("mouseout", () => button.dataset.hovered = "0");

}


function reportHovers(elements) {

  const hoveredIds = elements.filter(el => el.dataset.hovered === "1").map(el => el.id);

  document.getElementById("out").value = `${Math.floor(new Date() / 1000)}\n${JSON.stringify(hoveredIds)}`;

}



var buttons = Array.from(document.querySelectorAll("button"));

buttons.forEach(button => addEventListeners(button));

setInterval(() => reportHovers(buttons), 100);

<button id="b1">Button 1</button>

<button id="b2">Button 2</button>

<button id="b3">Button 3</button>


<textarea id="out"></textarea>


查看完整回答
反對(duì) 回復(fù) 2022-10-27
  • 3 回答
  • 0 關(guān)注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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