[英]Css Hover Effect with Jquery
.parent:hover.child
I'm trying to do this exact thing but only with jQuery.我正在尝试做这件事,但仅限于 jQuery。
I would suggest to use CSS over jquery ( if possible) otherwise you can use something like this我建议使用 CSS 而不是 jquery(如果可能的话),否则你可以使用这样的东西
$("div.myclass").hover(function() {
$(this).css("background-color","red")
});
You can change your selector as per your need.您可以根据需要更改选择器。
If you want to use this hover effect to multiple classes, you can use it like this如果你想对多个类使用这个悬停效果,你可以这样使用
$(".myclass, .myclass2").hover(function(e) {
$(this).css("background-color",e.type === "mouseenter"?"red":"transparent")
})
Check below code snippet for your concern.检查下面的代码片段以了解您的问题。 You can use the hover event with two functions as an argument.
您可以将悬停事件与两个函数一起用作参数。
$(document).ready(function(){ $(".parent").hover(function(){ $(this).addClass("hover"); },function(){ $(this).removeClass("hover"); }); })
.parent{ height:100px; width:200px; background-color:#F00; }.parent.child{ height:60px; width:160px; background-color:#0F0; margin:20px; }.parent.hover.child{ background-color:#00F; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="parent"> <div class="child"> </div> <div>
Best of luck.祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.