jQuery implements accordion small case

jQuery implements accordion small case

This article shares the specific code of jQuery to implement accordion for your reference. The specific content is as follows

Code demonstration effect:

1. Use jQuery and animation styles to switch the carousel images
2. Prerequisite: you need to import animate.css (download from the official website)

HTML code:

<head>
    <meta charset="UTF-8">
    <title>Accordion</title>
    <link rel="stylesheet" href="../animate.css">
    <link rel="stylesheet" href="css/index.css">
    <script src="../jquery-3.1.0.js"></script>
    <!-- <script src="js/accordionindex.js"></script>-->

</head>
<body>
    <div class="bg"></div>
    <div class="bg"></div>
    <div class="bg"></div>
    <div class="bg bg-active"></div>
    <div class="main">
        <ul>
            <li><div><p>Cross Fire</p></div></li>
            <li><div><p>Glory of the King</p></div></li>
            <li><div><p>Call of Duty</p></div></li>
            <li class="li-active"><div><p>League of Legends</p></div></li>
        </ul>
    </div>
</body>

Script code:

<script>
    $(function () {
       $("li").mouseenter(function () {
           //stop() stops the animation effect$(this).stop().animate({width:"700px"},1000,"linear").fadeIn();
           $(this).siblings("li").stop().animate({width:"100px"},1000,"linear").fadeIn();
           $(".bg").eq($(this).index()).siblings(".bg").stop().fadeOut();
           $(".bg").eq($(this).index()).stop().animate({top:"700px"},400,"linear").fadeIn();

       }); 
    });
</script>

CSS code:

*{
    margin: 0;
    padding: 0;
}
html,body, .bg{
    height: 700px;
    width: 1400px;
    overflow: hidden;
}
body{
    position: relative;
}
.bg{
    display: none;
}
.bg:nth-child(1){
    background:url("../images/1.jpg")no-repeat center/cover;
}
.bg:nth-child(2){
    background:url("../images/2.jpg")no-repeat center/cover;
}
.bg:nth-child(3){
    background:url("../images/3.jpg")no-repeat center/cover;
}
.bg:nth-child(4){
    background:url("../images/4.jpg")no-repeat center/cover;
}
/*Large background display*/
.bg-active{
    display: block;
}
.main{
    position: absolute;
    width: 1000px;
    height: 400px;
    /*background-color: pink;*/
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    margin: auto;
}
.main ul{
    list-style: none;
}
.main ul li{
    float: left;
    width: 100px;
    height: 400px;
    transition:right 1s;
}
/*Small background display*/
.main ul li.li-active{
    width: 700px;
    height: 400px;

}
.main ul li:nth-child(1){
     background: url("../images/1.jpg")no-repeat center/cover;
 }
.main ul li:nth-child(2){
    background: url("../images/2.jpg")no-repeat center/cover;
}
.main ul li:nth-child(3){
    background: url("../images/3.jpg")no-repeat center/cover;
}
.main ul li:nth-child(4){
    background: url("../images/4.jpg")no-repeat center/cover;
}
.main ul li div{
    height: 400px;
    width: 100px;
    background-color: rgba(0,0,0,.5);
}
.main ul li div p{
    color: #fff;
    padding: 40px;
    font-size: 20px;
    opacity: 0.5;
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • jQuery Easyui usage (I) foldable panel layout accordion menu
  • jQuery plugin to create accordion panel effect
  • jQuery makes an awesome accordion menu
  • Simple accordion effect example implemented by jQuery
  • Implementing accordion menu based on Jquery code
  • Make accordion based on slideDown and slideUp of jquery
  • jQuery to achieve accordion effect example code
  • jQuery accordion special effects plugin
  • Jquery component easyUi implements accordion (folding panel) example
  • jQuery to achieve accordion effect

<<:  Detailed explanation of the solution to permission denied in Linux

>>:  Solve the problem of shrinking Mysql transaction log and log files being too large to shrink

Recommend

The HTML 5 draft did not become a formal standard

<br />Yesterday I saw at W3C that the new HT...

Analysis of a MySQL deadlock scenario example

Preface Recently I encountered a deadlock problem...

Nginx configuration to achieve multiple server load balancing

Nginx load balancing server: IP: 192.168.0.4 (Ngi...

Some ways to solve the problem of Jenkins integrated docker plugin

Table of contents background Question 1 Error 2 E...

Detailed explanation of the use of Vue's new built-in components

Table of contents 1. Teleport 1.1 Introduction to...

How to successfully retrieve VMware Esxi root password after forgetting it

Prepare a CentOS6 installation disk (any version)...

CSS code to achieve 10 modern layouts

Preface I watched web.dev's 2020 three-day li...

Implementation of docker view container log command

Why should we read the log? For example, if the c...

How to deploy nextcloud network disk using docker

NextCloud You can share any files or folders on y...

Detailed explanation of styles in uni-app

Table of contents Styles in uni-app Summarize Sty...

Detailed explanation of the solution to the nginx panic problem

Regarding the nginx panic problem, we first need ...

MySQL intercepts the sql statement of the string function

1. left(name,4) intercepts the 4 characters on th...