gpt4 book ai didi

javascript - 如何组合这些悬停功能

转载 作者:行者123 更新时间:2023-11-28 20:53:45 24 4
gpt4 key购买 nike

我有很多跨度,我需要对其进行分组以在悬停后更改不透明度,所有这些跨度都需要具有唯一的 ID,有没有一种方法可以将所有这些悬停功能组合到一个功能中?

jQuery

//09    
$('#c_09_241a, #c_09_241b, #c_09_241c, #c_09_241d').hover(
function() {
$('#c_09_241a, #c_09_241b, #c_09_241c, #c_09_241d').stop(true, true).css('opacity','1');
},
function() {
$('#c_09_241a, #c_09_241b, #c_09_241c, #c_09_241d').stop(true, true).css('opacity','0');
});
$('#c_09_242a, #c_09_242b').hover(
function() {
$('#c_09_242a, #c_09_242b').stop(true, true).css('opacity','1');
},
function() {
$('#c_09_242a, #c_09_242b').stop(true, true).css('opacity','0');
});
$('#c_09_245a, #c_09_245b').hover(
function() {
$('#c_09_245a, #c_09_245b').stop(true, true).css('opacity','1');
},
function() {
$('#c_09_245a, #c_09_245b').stop(true, true).css('opacity','0');
});
$('#c_09_246a, #c_09_246b').hover(
function() {
$('#c_09_246a, #c_09_246b').stop(true, true).css('opacity','1');
},
function() {
$('#c_09_246a, #c_09_246b').stop(true, true).css('opacity','0');
});

//08
$('#c_08_235a, #c_08_235b, #c_08_235c, #c_08_235d').hover(
function() {
$('#c_08_235a, #c_08_235b, #c_08_235c, #c_08_235d').stop(true, true).css('opacity','1');
},
function() {
$('#c_08_235a, #c_08_235b, #c_08_235c, #c_08_235d').stop(true, true).css('opacity','0');
});
$('#c_08_236a, #c_08_236b').hover(
function() {
$('#c_08_236a, #c_08_236b').stop(true, true).css('opacity','1');
},
function() {
$('#c_08_236a, #c_08_236b').stop(true, true).css('opacity','0');
});
$('#c_08_239a, #c_08_239b').hover(
function() {
$('#c_08_239a, #c_08_239b').stop(true, true).css('opacity','1');
},
function() {
$('#c_08_239a, #c_08_239b').stop(true, true).css('opacity','0');
});
$('#c_08_240a, #c_08_240b').hover(
function() {
$('#c_08_240a, #c_08_240b').stop(true, true).css('opacity','1');
},
function() {
$('#c_08_240a, #c_08_240b').stop(true, true).css('opacity','0');
});

//07
$('#c_07_227a, #c_07_227b').hover(
function() {
$('#c_07_227a, #c_07_227b').stop(true, true).css('opacity','1');
},
function() {
$('#c_07_227a, #c_07_227b').stop(true, true).css('opacity','0');
});
$('#c_07_228a, #c_07_228b, #c_07_228c').hover(
function() {
$('#c_07_228a, #c_07_228b, #c_07_228c').stop(true, true).css('opacity','1');
},
function() {
$('#c_07_228a, #c_07_228b, #c_07_228c').stop(true, true).css('opacity','0');
});
$('#c_07_007a, #c_07_007b').hover(
function() {
$('#c_07_007a, #c_07_007b').stop(true, true).css('opacity','1');
},
function() {
$('#c_07_007a, #c_07_007b').stop(true, true).css('opacity','0');
});
$('#c_07_008a, #c_07_008b').hover(
function() {
$('#c_07_008a, #c_07_008b').stop(true, true).css('opacity','1');
},
function() {
$('#c_07_008a, #c_07_008b').stop(true, true).css('opacity','0');
});

HTML

<div id="rzuty09p" class="rzuty">
<span id="c_09_241a" class="mieszkanie" title=""></span>
<span id="c_09_241b" class="mieszkanie" title=""></span>
<span id="c_09_241c" class="mieszkanie" title=""></span>
<span id="c_09_241d" class="mieszkanie" title=""></span>
<span id="c_09_242a" class="mieszkanie" title=""></span>
<span id="c_09_242b" class="mieszkanie" title=""></span>
<span id="c_09_243" class="mieszkanie" title=""></span>
<span id="c_09_244" class="mieszkanie" title=""></span>
<span id="c_09_245a" class="mieszkanie" title=""></span>
<span id="c_09_245b" class="mieszkanie" title=""></span>
<span id="c_09_246a" class="mieszkanie nie" title=""></span>
<span id="c_09_246b" class="mieszkanie nie" title=""></span>
</div>

<div id="rzuty08p" class="rzuty">
<span id="c_08_235a" class="mieszkanie" title=""></span>
<span id="c_08_235b" class="mieszkanie" title=""></span>
<span id="c_08_235c" class="mieszkanie" title=""></span>
<span id="c_08_235d" class="mieszkanie" title=""></span>
<span id="c_08_236a" class="mieszkanie nie" title=""></span>
<span id="c_08_236b" class="mieszkanie nie" title=""></span>
<span id="c_08_237" class="mieszkanie" title=""></span>
<span id="c_08_238" class="mieszkanie" title=""></span>
<span id="c_08_239a" class="mieszkanie" title=""></span>
<span id="c_08_239b" class="mieszkanie" title=""></span>
<span id="c_08_240a" class="mieszkanie" title=""></span>
<span id="c_08_240b" class="mieszkanie" title=""></span>
</div>

<div id="rzuty07p" class="rzuty">
<span id="c_07_226" class="mieszkanie" title=""></span>
<span id="c_07_227a" class="mieszkanie" title=""></span>
<span id="c_07_227b" class="mieszkanie" title=""></span>
<span id="c_07_228a" class="mieszkanie" title=""></span>
<span id="c_07_228b" class="mieszkanie" title=""></span>
<span id="c_07_228c" class="mieszkanie" title=""></span>
<span id="c_07_229" class="mieszkanie nie" title=""></span>
<span id="c_07_005" class="mieszkanie" title=""></span>
<span id="c_07_006" class="mieszkanie" title=""></span>
<span id="c_07_007a" class="mieszkanie nie" title=""></span>
<span id="c_07_007b" class="mieszkanie nie" title=""></span>
<span id="c_07_008a" class="mieszkanie" title=""></span>
<span id="c_07_008b" class="mieszkanie" title=""></span>
</div>

最佳答案

您有三个选择:

  1. 使用您的类作为选择器:

    $('.mieszkanie').hover(
    function() {
    $(this).stop(true, true).css('opacity','1');
    },
    function() {
    $(this).stop(true, true).css('opacity','0');
    });
  2. 在同一选择器中添加所有 ID:

    $('#c_09_245a, #c_09_245b, #c_09_246a, #c_09_246b, #c_09_247a, #c_09_247b').hover(
    function() {
    $(this).stop(true, true).css('opacity','1');
    },
    function() {
    $(this).stop(true, true).css('opacity','0');
    });
  3. 创建两个函数来执行所需的操作以减少代码:

    function show () {
    $(this).stop(true, true).css('opacity','1');
    }

    function hide () {
    $(this).stop(true, true).css('opacity','0');
    }

    $(selector).hover(show, hide);

关于javascript - 如何组合这些悬停功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11987332/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com