Code Monkey home page Code Monkey logo

jquery-accordion's Introduction

typora-root-url
./

jquery-accordion

jquery封装的手风琴插件 注释详细欢迎下载效果展示

手风琴

1 HTML结构:

 <div id="wrap">
    <ul>
      <li ></li>

      <li ></li>

      <li ></li>

      <li ></li>

      <li ></li>

    </ul>

  </div>

2 css内容

* {
  margin: 0;
  padding: 0;
  list-style: none;
}

div {
  width: 1200px;
  height: 400px;
  border: 2px solid #000;
  margin: 100px auto;
}

ul {
  width: 1300px;
}

li {
  width: 240px;
  height: 400px;
  float: left;
  
}

3 js内容


$.fn.accordion = function(obj){
  obj.minWidth = obj.minWidth || 100;
  var lis = this.find('li');
  
  //动态的设置颜色
  lis.each(function(index, element){
    $(element).css('backgroundColor', obj.colors[index]);
  })

  //计算每一个li最大的宽度
  var liMaxW = this.width() - obj.minWidth* (lis.length - 1);
  var agvWidth = this.width() / lis.length;
  lis.mouseenter(function(){
    
    $(this).stop(true).animate({width: liMaxW}).siblings().stop(true).animate({width: obj.minWidth});
  })
  
  this.mouseleave(function(){
    //让所有的li恢复正常
    lis.stop(true).animate({width: agvWidth});
  })
  
}

jquery-accordion's People

Contributors

xingjygo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.