gpt4 book ai didi

javascript - 如果元素具有 A 类,则在鼠标离开时停止悬停效果

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

这是我的整个 jquery 代码:

$(function(){
$(".sc").hover(function(){
$(".sc span.L1").animate({marginRight:'0px'},100);
$(".sc span.L2").animate({marginRight:'28px'},200);
$(".sc span.L3").animate({marginRight:'5px'},300);
$(".sc span.L4").animate({marginRight:'19px'},400);
}, function(){
$(".sc span.L1").animate({marginRight:'0px'},100);
$(".sc span.L2").animate({marginRight:'0px'},200);
$(".sc span.L3").animate({marginRight:'0px'},300);
$(".sc span.L4").animate({marginRight:'0px'},400);
});
$(".sc").click(function(){
if ($(".sc div#trigger").hasClass('passive')){
$(".sc div#trigger").removeClass('passive');
$(".sc div#trigger").addClass('active');
}
else {
$(".sc div#trigger").addClass('passive');
$(".sc div#trigger").removeClass('active');
};

});

如果 div#trigger.hasClass('passive') 我想停止悬停效果。这意味着如果 div#trigger 的类是“被动的”,我希望悬停效果被禁用,而当类是“事件的”时,我希望悬停效果被启用..

如何使用此代码?!

if ($(".sc div#trigger").hasClass('passive')) {
// codes to stop hover effect
}

最佳答案

$(function(){
$(".sc .active").hover(function(){
$(".sc span.L1").animate({marginRight:'0px'},100);
$(".sc span.L2").animate({marginRight:'28px'},200);
$(".sc span.L3").animate({marginRight:'5px'},300);
$(".sc span.L4").animate({marginRight:'19px'},400);
}, function(){
$(".sc span.L1").animate({marginRight:'0px'},100);
$(".sc span.L2").animate({marginRight:'0px'},200);
$(".sc span.L3").animate({marginRight:'0px'},300);
$(".sc span.L4").animate({marginRight:'0px'},400);
});
$(".sc").click(function(){
if ($(".sc div#trigger").hasClass('passive')){
$(".sc div#trigger").removeClass('passive');
$(".sc div#trigger").addClass('active');
}
else {
$(".sc div#trigger").addClass('passive');
$(".sc div#trigger").removeClass('active');
};

});

关于javascript - 如果元素具有 A 类,则在鼠标离开时停止悬停效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12192809/

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