Home >Web Front-end >JS Tutorial >Sharing a simple method to implement jQuery accordion effect

Sharing a simple method to implement jQuery accordion effect

小云云
小云云Original
2017-12-30 15:30:361457browse

This article mainly teaches you how to simply implement the jQuery accordion effect. It has a certain reference value. Interested friends can refer to it. I hope it can help everyone.

js code:


<script type="text/javascript" src="jquery-3.0.0.js"></script>
<script type="text/javascript">
      $(function() {
        //获取所有li遍历
        $(".li_list").each(function() {
          //当鼠标进去当前li
          $(this).mouseenter(function() {
            //设置当前元素宽度
            $(this).stop()
                .animate({ "width": "600px" }, 500, "linear");
                //设置同胞元素宽度
                .siblings().stop()
                      .animate({ "width": "100px" }, 500, "linear");
          });
        });
      });
    </script>

css code:


##

 .li_list {
        width: 100px;
        height: 300px;
        list-style: none;
        float: left;
        overflow: hidden;
      }

      .li_list img {
        width: 100%;
        height: 100%;
      }

      .pbg {
        width: 600px;
        height: 300px;
        background: rgba(230, 0, 0, 0.5);
        text-align: center;
        line-height: 300px;
        float: left;
      }

      .pbg span {
        display: block;
        width: 100px;
        height: 300px;
        float: left;
      }

      .p1 {
        width: 500px;
        height: 300px;
        float: left;
      }
      .mo{
        width: 600px;
      }

html code:


<ul class="ul_list">
      <li class="li_list">
        <p class="pbg">
          <span>萌宠</span>
          <p class="p1">
            <img src="img/0.jpg" />
          </p>
        </p>
      </li>
      <li class="li_list">
        <p class="pbg">
          <span>萌宠</span>
          <p class="p1">
            <img src="img/1.jpg" />
          </p>
        </p>
      </li>
      <li class="li_list">
        <p class="pbg">
          <span>萌宠</span>
          <p class="p1">
            <img src="img/2.jpg" />
          </p>
        </p>
      </li>
      <li class="li_list mo">
        <p class="pbg">
          <span>萌宠</span>
          <p class="p1">
            <img src="img/3.jpg" />
          </p>
        </p>
      </li>
    </ul>

Related recommendations:

Detailed example of achieving accordion effect with pure CSS

jquery accordion focus animation

Use Bootstrap to achieve accordion effect

The above is the detailed content of Sharing a simple method to implement jQuery accordion effect. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn