SimpleSlidingAccordion code example

Example: SimpleSlidingAccordion

<?php
echo"SimpleSlidingAccordion.php";
?>
<html>
<head>
<script
  src="https://code.jquery.com/jquery-3.6.0.js"
  integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
  crossorigin="anonymous"></script>
</head>

<style>
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Josefin Sans', sans-serif;
}

body{
  margin: 20px;
  background: #f4f4f6;
}

.accordion{
    width: 450px;
    height: 60px;
    margin: 0 auto;
    background: #fff;
    border-radius: 3px;
    box-shadow: 0 0 5px rgba(225,225,225,1);
    overflow: hidden;
    transition: height 0.3s ease;
    margin-bottom: 20px;
}

.accordion .accordion_tab{
  padding: 20px;
  cursor: pointer;
  user-select: none;
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: relative;
}

.accordion .accordion_tab .accordion_arrow{
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 20px;
  width: 15px;
  height: 15px;
  transition: all 0.3s ease;
}

.accordion .accordion_tab .accordion_arrow img{
  width: 100%;
  height: 100%;
}

.accordion .accordion_tab.active .accordion_arrow{
  transform: translateY(-50%) rotate(180deg);
}

.accordion.active{
  height: 320px;
}

.accordion .accordion_content{
  padding: 20px;
  border-top: 1px solid #e9e9e9;
}

.accordion .accordion_content .accordion_item{
  margin-bottom: 20px;
}

.accordion .accordion_content .accordion_item p.item_title{
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 18px;
  color: #6adda2;
}

.accordion .accordion_content .accordion_item p:last-child{
  color: #9a9b9f;
  font-size: 14px;
  line-height: 20px;
}
</style>
<body>

<div class="wrapper">
  <div class="accordion active">
    <div class="accordion_tab active">
        Sliding Accordion
        <div class="accordion_arrow">
          <img src="https://i.imgur.com/PJRz0Fc.png" alt="arrow">
      </div>
    </div>
    <div class="accordion_content">
      <div class="accordion_item">
        <p class="item_title">Description</p>
        <p>bgggggggggggg</p>
      </div>
     
    </div>
  </div>
  <div class="accordion">
    <div class="accordion_tab active">
       Sliding Accordion
        <div class="accordion_arrow">
          <img src="https://i.imgur.com/PJRz0Fc.png" alt="arrow">
      </div>
    </div>
    <div class="accordion_content">
      <div class="accordion_item">
        <p class="item_title">Description</p>
        <p>my first script</p>
      </div>
      
    </div>
  </div>
  
</div>
</body>

<script>
$(".accordion_tab").click(function(){
    $(".accordion_tab").each(function(){
      $(this).parent().removeClass("active");
      $(this).removeClass("active");
    });
    $(this).parent().addClass("active");
    $(this).addClass("active");
});


</script>
</html>

Tags:

Php Example