Home > Web Front-end > JS Tutorial > slideToggle+slideup implements the mobile phone folding menu effect example code

slideToggle+slideup implements the mobile phone folding menu effect example code

小云云
Release: 2018-01-10 13:30:06
Original
1806 people have browsed it

This article mainly introduces slideToggle+slideup in detail to realize the folding menu effect on the mobile phone. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

For the effect of collapsing menus, there are many plug-ins on the Internet, such as bootstrap's Collapse, which are easy to use and very simple. However, if you are not using the bootstrap framework, it will cause a lot of unnecessary trouble, such as the default style. Modified, code redundancy, etc. Generally, there are many jQuery-based plug-ins on the Internet, but they are too cumbersome. Today I will tell you how to use jQuery’s own functions to achieve this effect. Not much to say, just go straight to it. Code:

HTML part:


<p class="box">
  <!-- 内容-->
  <ul class="inner">
    <li class="inner_title">绿色校园<span></span></li>
    <ol class="inner_style">
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
    </ol>
    <li class="inner_title">绿色校园<span></span></li>
    <ol class="inner_style">
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
    </ol>
    <li class="inner_title">绿色校园<span></span></li>
    <ol class="inner_style">
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
      <li>篮球场</li>
    </ol>
  </ul>
</p>
Copy after login

CSS part:


##

<style>
  body{
    background: #dddddd;
  }
  .inner{
    background: #fff;
    width: 100%;
    overflow: hidden;
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .inner .inner_title{
    background-color: #fff;
    width: 100%;
    padding: 0 2.5%;
    border-bottom: 1px solid #efefef;
    color: #343434;
    height: 40px;
    line-height: 40px;
    font-size: 16px;
    position: relative;
  }
  .inner .inner_title span{
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    margin-top: -10px;
    right: 6%;
    background: url("images/arow_left.png") no-repeat center;
  }
  .inner .inner_title.active{
    color: #4db780;
  }
  .inner .inner_title.active span{
    background: url("images/arow_down.png") no-repeat center;
  }
  /*弹出的二级分类处理*/
  .inner .inner_style{
    margin: 0;
    list-style: none;
    width: 100%;
    background-color: #efefef;
    overflow: hidden;
    padding: 15px 3%;
  }
  .inner .inner_style li{
    float: left;
    color: #333;
    font-size: 14px;
    width: 21%;
    text-align: center;
    line-height: 30px;
    margin-right: 5%;
  }
</style>
Copy after login

js Part (remember to introduce jQuery):


##

<script>
  /**处理折叠效果**/
  (function ($) {
    $.fn.Fold = function (options) {
      //默认参数设置
      var settings = {
        speed: 300 //折叠速度(值越大越慢)
      }
      //不为空则合并参数
      if (options)
        $.extend(settings, options);

      //遵循链式原则
      return this.each(function () {
        //为每个li元素绑定点击事件
        $("> li", this).each(function () {
          $(this).bind("click", function () {
            //单击之前先判断当前菜单是否折叠
            if($(this).hasClass(&#39;active&#39;)){//折叠状态
              $(".inner ol").slideUp(&#39;500&#39;);//使用slideup()折叠其他选项
              $(this).removeClass(&#39;active&#39;);//移除选中样式
            }else{//打开状态
              $(this).siblings(&#39;li&#39;).removeClass(&#39;active&#39;);
              $(".inner ol").slideUp(&#39;500&#39;);//使用slideup()折叠其他选项
              $(this).addClass(&#39;active&#39;)//添加选中样式
              $(this).next("ol").slideToggle(settings.speed);
            }
          });
        });
        //默认折叠
        $("> ol", this).hide();
      });
    }
  })(jQuery);
  $(".inner").Fold();//调用
</script>
Copy after login

The effect is as follows:

Related recommendations:

A brief analysis of the difference between toggle and slideToggle in jquery

jquery hides, displays events and prompts callback, fade in and out fadeToggle, slide in and slide out slideToggle , animation animate stops animation stop

JQury slideToggle flashing problem and solution

The above is the detailed content of slideToggle+slideup implements the mobile phone folding menu effect example code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template