我想在鼠标悬停和鼠标移开时更改 div 元素的背景图像。此外,当 div 元素处于活动状态时,它应该只使用一张图片。这可以通过 Jquery 或 Javascript 来实现吗?
上面是 HTML 代码,其中所有三个项目都具有相同的类名,但我添加了自定义图像而不是图标
var div1 = document.getElementById("custom_image");
var div2 = document.getElementById("inner_id");
setInterval(function() {
if ($('#custom_image').hasClass("active")) {
div2.onmouseover = function() {
$(div2).find("[id=no_hover_]").attr("src", "img/no-dollar_white.png");
};
div2.onmouseout = function() {
$(div2).find("[id=no_hover]").attr("src", "img/no-dollar_white.png");
};
} else {
div2.onmouseover = function() {
$(div2).find("[id=no_hover_]").attr("src", "img/no-dollar_white.png");
};
div2.onmouseout = function() {
$(div2).find("[id=no_hover]").attr("src", "img/no-dollar_blue.png");
};
}
}, 1);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-md-6">
<div class="how-app-work-content-wrap">
<div class="title">
<h3>How are we different?</h3>
</div>
<!-- /.title -->
<div class="how-app-work-content" id="how-app-work-slider-pager">
<a href="#" class="pager-item active" data-slide-index="0">
<div class="single-how-app-work ">
<div class="icon-box">
<div class="inner">
<i class="far fa-thumbs-up"></i>
</div>
<!-- /.inner -->
</div>
<!-- /.icon-box -->
<div class="text-box">
<h4>Be Independent</h4>
<p>We use a customized application tobe <br /> specifically designed a testing gnose <br /> to keep away for people.</p>
</div>
<!-- /.text-box -->
</div>
</a>
<!-- /.single-how-app-work -->
<a href="#" class="pager-item" data-slide-index="1">
<div class="single-how-app-work">
<div class="icon-box">
<div class="inner">
<i class="far fa-handshake-o"></i>
</div>
慕容森
呼如林
暮色呼如
相关分类