Home  >  Article  >  Web Front-end  >  Make a simple accordion with jQuery

Make a simple accordion with jQuery

小云云
小云云Original
2018-01-12 09:45:391086browse

This article mainly introduces the simple production of jQuery accordion in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

First of all, let’s make a simple jQuery rendering. The specific content is as follows

The css code is as follows:


<style type="text/css" media="screen">
  *{margin: 0;padding: 0;}
  ul,li{list-style:none}
   ul {
    width: 300px;
    background: yellow;
    margin: 50px auto;
  }
  ul>li{
    line-height: 50px;
    text-align: center;
    border-bottom: 1px solid #ccc;
  }
  ul>li>ol{
    background: blue;
    display: none;
  }
  ul>li>ol>li{
    line-height: 50px;
  }
</style>


HTML code is as follows:


<ul id="ul">

  <li>
    <p>jquery的核心函数</p>
    <ol>
      <li>jQuery([selector,[context]])</li>
      <li>jQuery(html,[ownerDoc])1.8</li>
      <li>jQuery(callback) </li>
      <li>jQuery.holdReady(hold)1.6+</li>
    </ol>
  </li>
  <li>
      <p>jQuery的效果</p>
    <ol>
      <li>hide 显示和隐藏</li>
      <li>slideDown 只对高度有效</li>
      <li>fadeIn 淡入效果</li>
      <li>slideToggle 淡入和淡出效果</li>
    </ol>
  </li>
  <li>
      <p>jQuery的属性</p>
    <ol>
      <li>attr 设置或返回的元素</li>
      <li>removeAttr 从每个元素中删除一个元素</li>
      <li>prop 获取第一个元素的属性</li>
      <li>removeProp prop()方法设置属性集</li>
    </ol>
  </li>
  <li>
      <p>jQuery的事件</p>
    <ol>
      <li>off 在元素上移除多个事件的处理函数</li>
      <li>bind 为每个元素绑定事件处理函数</li>
      <li>one 为每个匹配元素绑定一次性处理函数</li>
      <li>trigger 在每个匹配的元素上触发某类事件</li>
    </ol>
  </li>

</ul>


##jQuery code is as follows:


<script src="jquery.min.js" type="text/javascript"charset="utf-8"></script>
<script type="text/javascript">
 $("#ul>li>p").click(function(){

  $(this).nextAll().slideDown()
  .end().parent().siblings()
  .children("ol").hide();
 }); 
</script>


The rendering is as follows:

Related recommendations:

JQuery implements simple Accordion effect example sharing

Example detailed explanation jQuery implements accordion menu, hierarchical menu, top menu, seamless scrolling effect

jQuery implements drop-down menu Accordion effect sharing

The above is the detailed content of Make a simple accordion with jQuery. 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