如何使用切换创建显示按钮上方的内容?

时间:2018-11-28 06:33:57

标签: javascript jquery html

在这里,我创建了慢动作切换内容...但是它显示文本,例如传播效果 如何消除这种扩散效应

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 extra-p">
          <div class="pannel" style="display: none;">
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
          tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
          quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
          consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
          cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
          proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
         </div>
        </div><!--md-12-->

        <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12 anc-btn">
        <button class="btn btn-orange tip-btn">read more</button>
        </div><!--md-2-->
        <script type="text/javascript">
         $(document).ready(function(){
    $(".tip-btn").click(function(){
        $(".pannel").toggle("slow");
        });
     });
        </script>


</body>
</html>

? 引导jquery javascropt

2 个答案:

答案 0 :(得分:1)

您需要使用toggle而不是slideToggle,它可以帮助您显示而不散布效果

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
  <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 extra-p">
      <div class="pannel" style="display: none;">
      <p>1 . Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
      tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
      quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
      consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
      cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
      proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
     </div>
     <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12 anc-btn">
        <button class="btn btn-orange tip-btn">read more 1</button>
        </div><!--md-2-->
    </div><!--md-12-->
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 extra-p">
        <div class="pannel" style="display: none;">
        <p>2. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
       </div>
       <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12 anc-btn">
          <button class="btn btn-orange tip-btn">read more 2</button>
          </div><!--md-2-->
      </div><!--md-12-->
      <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 extra-p">
        <div class="pannel" style="display: none;">
        <p>3. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
       </div>
       <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12 anc-btn">
          <button class="btn btn-orange tip-btn">read more 3</button>
          </div><!--md-2-->
      </div><!--md-12-->
      <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 extra-p">
        <div class="pannel" style="display: none;">
        <p>4. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
        tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
        quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
        consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
        cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
        proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
       </div>
       <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12 anc-btn">
          <button class="btn btn-orange tip-btn">read more 4</button>
          </div><!--md-2-->
      </div><!--md-12-->
        <script type="text/javascript">
         $(document).ready(function(){
    $(".tip-btn").click(function(){
         $(this).closest('.extra-p').find('.pannel').slideToggle("slow");
        });
     });
        </script>


</body>
</html>

答案 1 :(得分:0)

您可以在此处使用两种方法来缓慢切换内容:

1 service如上面的答案

  1. $(".pannel").slideToggle("slow")以显示和隐藏内容

用于多个按钮

$(".pannel").fadeToggle("slow);

让div1,div2和div3为要切换的三个div的ID

<button class="tip-btn" check="div1"></button>
<button class="tip-btn" check="div2"></button>
<button class="tip-btn" check="div3"></button>

希望有帮助。