Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery addClass类已被psuedo(:hover)_Jquery_Css_Naming Conventions_Pseudo Class - Fatal编程技术网

jQuery addClass类已被psuedo(:hover)

jQuery addClass类已被psuedo(:hover),jquery,css,naming-conventions,pseudo-class,Jquery,Css,Naming Conventions,Pseudo Class,我编写了一个javascript/jQuery解决方案,在鼠标离开图标(元素)后,将:hover css保留在图标(元素)上,并保留在一个lightbox上,该lightbox会触发鼠标悬停在元素上-我希望保持图标样式化,以便您可以看到是什么激活了lightbox 在我使用的css中: #toolbar-content li:hover, .tt-li-text{ color: rgba(255, 255, 255, 0.93); text-shadow: 1px 1px 1px #33

我编写了一个javascript/jQuery解决方案,在鼠标离开图标(元素)后,将:hover css保留在图标(元素)上,并保留在一个lightbox上,该lightbox会触发鼠标悬停在元素上-我希望保持图标样式化,以便您可以看到是什么激活了lightbox

在我使用的css中:

#toolbar-content li:hover, .tt-li-text{
  color: rgba(255, 255, 255, 0.93);
  text-shadow: 1px 1px 1px #333333;
}
#工具栏内容li:hover
用于原始的悬停样式,
.tt li文本
是我在jQuery addClass中使用的,如下所示:

$("#toolbar-content li:nth-child("+mi+") i").removeClass("tt-li-text");
完整的代码是:

function hvrOn(mi)
{   
// Select nth-child of menu array - e.g. passed by afterBoxStart: hvrOn(1)
$("#toolbar-content li:nth-child("+mi+")").addClass("tt-li"); //div
$("#toolbar-content li:nth-child("+mi+") i").addClass("tt-li-text"); //icon
 return true;
}
function hvrOff(mi)
{
// Select nth-child of menu array - e.g. passed by afterBoxEnd: hvrOff(1) 
$("#toolbar-content li:nth-child("+mi+")").removeClass("tt-li");
$("#toolbar-content li:nth-child("+mi+") i").removeClass("tt-li-text");
return true;
}

我的问题是,是否有可能以某种方式在addClass中重用原来的css类名
#工具栏内容li:hover
,还是我现在的做法——使用第二个名称而不使用:hover?

1)Java不是Javascript。2)
:hover
是一个伪类,不能通过JS/jQuery进行设置。你可以做的是在hover上添加一个
.active
类,而不是在hover out上删除它,这样活动的颜色就会保留下来。您需要监听事件并在悬停状态下添加一个类,而在移出时不删除它。我最近回答了另一个使用这个概念的问题:@Jeremy@GolezTrol-我有一个有效的解决方案。我的问题是关于类名的。我确信您不能使用包含以下内容的类名:hover in addClass/removeClass,但希望检查此处以确保。这样就不用像我现在这样在类名上加倍了。