jQuery implements breathing carousel

jQuery implements breathing carousel

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

HTML

<div class="all" id="box">
        <div class="screen">
            <ul>
                <li><img src="images/01.jpg" width="500" height="200" /></li>
                <li><img src="images/02.jpg" width="500" height="200" /></li>
                <li><img src="images/03.jpg" width="500" height="200" /></li>
                <li><img src="images/04.jpg" width="500" height="200" /></li>
                <li><img src="images/05.jpg" width="500" height="200" /></li>
            </ul>
            <ol>
                <li class="current">1</li>
                <li>2</li>
                <li>3</li>
                <li>4</li>
                <li>5</li>
            </ol>
        </div>
        <div id="arr">
            <span id="left">&lt;</span>
            <span id="right">&gt;</span>
        </div>
</div>

CSS

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

        .all {
            width: 500px;
            height: 200px;
            padding: 7px;
            border: 1px solid #ccc;
            margin: 100px auto;
            position: relative;
        }

        .screen {
            width: 500px;
            height: 200px;
            overflow: hidden;
            position: relative;
        }

        .screen li {
            width: 500px;
            height: 200px;
            overflow: hidden;
            float: left;
        }

        .screen ul {
            position: absolute;
            left: 0;
            top: 0px;
            width: 2500px;
        }

        .all ol {
            position: absolute;
            right: 10px;
            bottom: 10px;
            line-height: 20px;
            text-align: center;
        }

        .all ol li {
            float: left;
            width: 20px;
            height: 20px;
            background: #fff;
            border: 1px solid #ccc;
            margin-left: 10px;
            cursor: pointer;
        }

        .all ol li.current {
            background: yellow;
        }

        #arr {
            display: none;
        }

        #arr span {
            width: 40px;
            height: 40px;
            position: absolute;
            left: 5px;
            top: 50%;
            margin-top: -20px;
            background: #000;
            cursor: pointer;
            line-height: 40px;
            text-align: center;
            font-weight: bold;
            font-family: 'bold';
            font-size: 30px;
            color: #fff;
            opacity: 0.3;
            border: 1px solid #fff;
        }

        #arr #right {
            right: 5px;
            left: auto;
        }

JS code

$(function () {
        var index = 0;
        //Mouse enters $('#box').mouseenter(function(){
            $('#arr').show();
        })
        //Mouse out of $('#box').mouseleave(function(){
            $('#arr').hide();
        })
        $('#right').click(function(){
            if(index == $('.screen>ul>li').length-1){ //The last one index = 0;
            }else {
               index++; 
            }
            $('.screen>ul>li').eq(index).fadeIn(200).siblings('li').fadeOut(200);
            //The page number below corresponds to the highlight $('.screen>ol>li').eq(index).addClass('current').siblings('li').removeClass('current')
        })
        $('#left').click(function(){
            if(index == 0){ //The first index = $('.screen>ul>li').length-1;
            }else {
                index--;
            }
            $('.screen>ul>li').eq(index).fadeIn(200).siblings('li').fadeOut(200);
            //The page number below corresponds to the highlight $('.screen>ol>li').eq(index).addClass('current').siblings('li').removeClass('current')
        })
        //Click the page number to play the carousel image$('.screen>ol>li').click(function(){
            index = $(this).index()
            $('.screen>ul>li').eq(index).fadeIn(200).siblings('li').fadeOut(200);
            $('.screen>ol>li').eq(index).addClass('current').siblings('li').removeClass('current')
        })
 });

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:
  • Native JS to implement breathing carousel
  • jQuery achieves breathing carousel effect

<<:  Implementation of running springboot project with Docker

>>:  XHTML introductory tutorial: Application of table tags

Recommend

How to start and restart nginx in Linux

Nginx (engine x) is a high-performance HTTP and r...

Introduction to the use of anchors (named anchors) in HTML web pages

The following information is compiled from the Int...

MySQL 8.0.18 installation and configuration method graphic tutorial (linux)

This article records the installation and configu...

jQuery plugin to implement accordion secondary menu

This article uses a jQuery plug-in to create an a...

MySQL 5.7.27 installation and configuration method graphic tutorial

MySQL 5.7.27 detailed download, installation and ...

Nodejs converts JSON string into JSON object error solution

How to convert a JSON string into a JSON object? ...

Detailed Example of CSS3 box-shadow Property

CSS3 -- Adding shadows (using box shadows) CSS3 -...

MySQL Series 14 MySQL High Availability Implementation

1. MHA ​By monitoring the master node, automatic ...

A brief discussion on VUE uni-app's commonly used APIs

Table of contents 1. Routing and page jump 2. Int...

Understanding and solutions of 1px line in mobile development

Reasons why the 1px line becomes thicker When wor...

Detailed explanation of computed properties in Vue

Table of contents Interpolation Expressions metho...

Implementation steps for docker deployment lnmp-wordpress

Table of contents 1. Experimental Environment 2. ...