I would like to show and hide a section which is landing over a div as a second screen when i hover one the section i want it to hide and show here's what I've done lately. I have tried a lot of things but nothing works.
<div class=" banner">
<div class="section-left">
<section class="ha">
<p> الوافد الجديد</p>
<a href="#"><h6> تسوق الان</h6></a>
</section>
</div>
<div class="section-mid">
<section>
<p> الوافد الجديد</p>
<a href="#"><h6> تسوق الان</h6></a>
</section>
</div>
<div class="section-right">
<section>
<p> الوافد الجديد</p>
<a href="#"><h6> تسوق الان</h6></a>
</section>
</div>
.section-left {
background-image: url("img/Layer-44.jpg");
z-index: 99999;
position: absolute;
display: inline-block;
left: 90px;
width: 309px;
height: 180px;
}
.ha {
background-color:rgba(187,166,153,.6);
width: 100%;
height:100%;
display: none;
}
.section-left p {
text-align: center;
font-family: Droid Arabic Kufi;
color: #fff;
font-size: 18px;
padding-top: 60px;
position: relative;
}
.section-left p:after{
background-image: url("img/lin.png");
display: block;
content: " ";
margin-left: 130px;
margin-top: 15px;
background-color: red;
width: 64px;
height: 1px;
}
.section-left h6{
text-align: center;
font-family: Droid Arabic Kufi;
color: #fff;
font-size: 18px;
position: absolute;
top: 110px;
left: 110px;
}
$(function() {
$(".section-left").hover(function() {
$(this).has(".ha").show();
}, function() {
$(this).has(".ha").hide();
});
});
$(document).ready(function() {
$("#abc").hide();
$('#xyz').click(function() {
$("#abc").show();
$("#xyz").hide();
});
$('#xyz').click(function() {
$("#abc").show();
$("#xyz").hide();
});
});
$(".section-left").mouseenter(function(){
$(".section-left").hide();
});
$(".section-left").mouseleave(function(){
$(".section-left").show();
});
This might help.
The main problem is because the has()
method returns a boolean which is then throwing an error as you call show()
or hide()
on it. Instead, use find()
which will return a jQuery object containing the .ha
element. Also note that you can use the toggle()
method in a single hover
event handler over hide()
/ show()
in separate functions. Something like this:
$(function() { $(".section-left").hover(function() { $(this).find(".ha").toggle(); }); });
.section-left { background-image: url("img/Layer-44.jpg"); z-index: 99999; position: absolute; display: inline-block; left: 90px; width: 309px; height: 180px; } .ha { background-color:rgba(187,166,153,.6); width: 100%; height:100%; display: none; } .section-left p { text-align: center; font-family: Droid Arabic Kufi; color: #fff; font-size: 18px; padding-top: 60px; position: relative; } .section-left p:after{ background-image: url("img/lin.png"); display: block; content: " "; margin-left: 130px; margin-top: 15px; background-color: red; width: 64px; height: 1px; } .section-left h6{ text-align: center; font-family: Droid Arabic Kufi; color: #fff; font-size: 18px; position: absolute; top: 110px; left: 110px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="banner"> <div class="section-left"> <section class="ha"> <p>الوافد الجديد</p> <a href="#"><h6> تسوق الان</h6></a> </section> </div> <div class="section-mid"> <section> <p>الوافد الجديد</p> <a href="#"><h6> تسوق الان</h6></a> </section> </div> <div class="section-right"> <section> <p>الوافد الجديد</p> <a href="#"><h6> تسوق الان</h6></a> </section> </div> </div>
Why use JavaScript when you dont have too?
HTML:
<div id="hovering">
<div id="disappearing">
</div>
</div>
Style:
#hovering {
width: 200px;
height: 200px;
background-color: red;
}
#disappearing {
width: 100px;
height: 100px;
background-color: green;
}
#hovering:hover #disappearing {
display: none;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.