使用jquery隐藏、显示

hide, show using jquery

本文关键字:显示 隐藏 jquery 使用      更新时间:2023-09-26

我想显示和隐藏一个部分,当我悬停在我希望它隐藏的部分上时,它将作为第二个屏幕降落在div上。我尝试了很多方法,但都不起作用。

<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();
});

这可能会有所帮助。

主要问题是因为has()方法返回一个布尔值,当您对其调用show()hide()时,它会抛出一个错误。相反,使用find(),它会返回一个包含.ha元素的jQuery对象。另外请注意,您可以在单独的函数中使用hide()/show()上的单个hover事件处理程序中的toggle()方法。类似这样的东西:

$(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>

为什么不用JavaScript?

HTML:

<div id="hovering">
<div id="disappearing">
</div>
</div>

样式:

#hovering {
  width: 200px;
  height: 200px;
  background-color: red;
}
#disappearing {
  width: 100px;
  height: 100px;
  background-color: green;
}
#hovering:hover #disappearing {
  display: none;
}

https://jsfiddle.net/ww6rywdd/