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

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

CSS 混合混合模式 + JS

CSS 混合混合模式 + JS

暮色呼如 2023-12-19 20:39:36
所以我有一個自定義的 js 光標(它跟隨鼠標光標有延遲),其背景顏色為 #000,混合混合模式設置為差異。我的身體背景顏色和文本設置為#fff?,F在,我有一個帶有文本“HELLO”的 p 標簽。我希望僅顯示“H”一詞和“O”,所以我創建了一個顏色設置為#000的跨度。當我將鼠標懸停在 P 標簽上時,由于混合混合模式,我可以看到“ELL”我想要的詞,但是“H”這個詞和“O”得到”看不見”。當光標移到它上面時如何使它們可見? (如果光標沒有覆蓋整個單詞,則只是光標懸停的每個單詞的一部分,而不是整個單詞)有什么解決辦法嗎?我嘗試改變“H”的顏色和“O”在 mouseenter/mouseleave 上,但它沒有按預期工作。const cursor = document.querySelector('.cursor')const wuc = document.querySelectorAll('.wuc')document.addEventListener('mousemove', e => {    cursor.setAttribute('style', 'top: ' + e.clientY+'px; left: '+e.clientX+'px;')})wuc.forEach((wuc) => {    wuc.addEventListener('mouseenter', () => {        wuc.style.color = '#fff'    })    wuc.addEventListener('mouseleave', () => {        wuc.style.color = '#000'    })})body {    background-color: #fff;    color: #fff;}.cursor {    width: 5vw;    height: 5vw;    transform: translate(-2.5vw, -2.5vw);    position: fixed;    transition-duration: 200ms;    transition-timing-function: ease-out;    background-color: #000;    border-radius: 50%;    mix-blend-mode: difference;}p {    margin-left: 30vw;    margin-top: 40vh;}.wuc {    color: #000;} <div class="cursor"></div>    <p class="container">       <span class="wuc">H</span>ELL<span class="wuc">O</span>    </p>
查看完整描述

1 回答

?
倚天杖

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

我將使用與自定義光標相同位置的 radial-gradient 為文本著色


const cursor = document.querySelector('.cursor')

document.addEventListener('mousemove', e => {

  cursor.setAttribute('style', 'top: ' + e.clientY + 'px; left: ' + e.clientX + 'px;');

  document.body.setAttribute('style', '--x: ' + e.clientX + 'px;--y:' + e.clientY + 'px;');

})

body {

  background-color: #fff;

  color: #fff;

}


.cursor {

  width: 5vw;

  height: 5vw;

  transform: translate(-2.5vw, -2.5vw);

  position: fixed;

  transition-duration: 200ms;

  transition-timing-function: ease-out;

  background-color: #000;

  border-radius: 50%;

  mix-blend-mode: difference;

}


p {

  margin-left: 30vw;

  margin-top: 40vh;

}


.wuc {

  background: 

    radial-gradient(farthest-side, #fff 99.5%, #000 100%) calc(var(--x,0px) - 2.5vw) calc(var(--y,0px) - 2.5vw)/5vw 5vw fixed no-repeat,

    #000;

  -webkit-background-clip:text;

  background-clip:text;

  -webkit-text-fill-color: transparent;

  color:transparent;

  

}

<div class="cursor"></div>

<p class="container">

  <span class="wuc">H</span>ELL<span class="wuc">O</span>

</p>


查看完整回答
反對 回復 2023-12-19
  • 1 回答
  • 0 關注
  • 148 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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