search
HomeWeb Front-endJS TutorialImplementing automatic carousel carousel effects based on jQuery_jquery

The example in this article describes the implementation of automatic carousel carousel effects with jQuery. Share it with everyone for your reference. The details are as follows:
This is an automatic carousel carousel effect code based on jQuery. The implementation process is very simple.
Operation rendering: -------------------View the effect Download the source code-------------------

Brief tutorial
jquery.caroursel.js is a very practical jQuery carousel plug-in that can automatically rotate. This carousel stacks pictures and pushes the pictures to the front in turn for display, forming a carousel effect.
How to use
The jQuery carousel plug-in needs to import jQuery, jquery.carousel.js file.

<script src="js/jquery.min.js"></script>
<script src="js/jquery.carousel.js"></script>    

HTML structure

The jQuery carousel plug-in uses a

as the wrapping element. Inside it is an unordered list for placing images, and two
elements as front and back navigation buttons.
<div class="caroursel rotator-demo">
 <ul class="rotator-list">
 <li class="rotator-item"><img  src="/static/imghwm/default1.png"  data-src="image/1.jpg"  class="lazy" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
 <li class="rotator-item"><img  src="/static/imghwm/default1.png"  data-src="image/2.jpg"  class="lazy" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
 <li class="rotator-item"><img  src="/static/imghwm/default1.png"  data-src="image/3.jpg"  class="lazy" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
 </ul>
 <div class="rotator-btn rotator-prev-btn"></div>
 <div class="rotator-btn rotator-next-btn"></div>
</div>    

The number of pictures needs to be an odd number, otherwise there will be some abnormalities in the display. This is a small bug of this plug-in.
CSS style

You need to add some necessary CSS styles below for this carousel effect.

.rotator-main {
 position: relative;
 width: 900px;
 height: 400px
}
 
.rotator-main a, .rotator-main img { display: block; }
 
.rotator-main .rotator-list {
 width: 900px;
 height: 400px
}
 
.rotator-main .rotator-list .rotator-item {
 position: absolute;
 left: 0px;
 top: 0px
}
 
.rotator-main .rotator-btn {
 position: absolute;
 height: 100%;
 width: 100px;
 top: 0px;
 z-index: 10;
 opacity: 0;
}
 
.rotator-main .rotator-prev-btn {
 left: 0px;
 background: url("../image/btn_l.png") no-repeat center center;
 background-color: red
}
 
.rotator-main .rotator-next-btn {
 right: 0px;
 background: url("../image/btn_r.png") no-repeat center center;
 background-color: red
}    

Initialize plugin

After the page DOM element is loaded, you can initialize the carousel plug-in through the following method.
Caroursel.init($('.caroursel')) If you need to customize some parameters, you can set the data-setting attribute in the top-level

element.

<div class="caroursel rotator-main"
  data-setting = '{
  "width":1000,   //旋转木马的宽度
  "height":270,   //旋转木马的高度
  "posterWidth":640, //当前显示的图片的宽度
  "posterHeight":270, //当前显示的图片的高度
  "scale":0.8,   //缩放值
  "algin":"middle",  //对齐方式
  "speed":"1000",  //动画速度
  "isAutoplay":"true", //自动播放
  "dealy":"1000"  //延迟时间
}'>    

Tips: If the browser does not work properly, you can try switching the browsing mode.

The jQuery implementation of the automatic carousel carousel effect code shared with you is as follows

<html lang="zh">
<head>
 <meta charset="UTF-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>jQuery自动轮播旋转木马插件</title>
 <link rel="stylesheet" type="text/css" href="css/normalize.css" />
 <link rel="stylesheet" type="text/css" href="css/default.css">
 <link type="text/css" rel="stylesheet" href="css/carousel.css">
 <style type="text/css">
 .caroursel{margin:150px auto;}
 </style>
 <!--[if IE]>
 <script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
 <![endif]-->
</head>
<body>
 <article class="htmleaf-container">
 <header class="htmleaf-header">
 <h1 id="jQuery自动轮播旋转木马插件">jQuery自动轮播旋转木马插件</h1>
 
 </header>
 <div class = "caroursel poster-main" data-setting = '{
  "width":1000,
  "height":270,
  "posterWidth":640,
  "posterHeight":270,
  "scale":0.8,
  "dealy":"2000",
  "algin":"middle"
 }'>
  <ul class = "poster-list">
  <li class = "poster-item"><img  src="/static/imghwm/default1.png"  data-src="image/1.jpg"  class="lazy" width = "100%"    style="max-width:90%" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
  <li class = "poster-item"><img  src="/static/imghwm/default1.png"  data-src="image/2.jpg"  class="lazy" width = "100%"    style="max-width:90%" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
  <li class = "poster-item"><img  src="/static/imghwm/default1.png"  data-src="image/3.jpg"  class="lazy" width = "100%"    style="max-width:90%" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
  <li class = "poster-item"><img  src="/static/imghwm/default1.png"  data-src="image/4.jpg"  class="lazy" width = "100%"    style="max-width:90%" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
  <li class = "poster-item"><img  src="/static/imghwm/default1.png"  data-src="image/5.jpg"  class="lazy" width = "100%"    style="max-width:90%" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
  <li class = "poster-item"><img  src="/static/imghwm/default1.png"  data-src="image/6.jpg"  class="lazy" width = "100%"    style="max-width:90%" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
  <li class = "poster-item"><img  src="/static/imghwm/default1.png"  data-src="image/1.jpg"  class="lazy" width = "100%"    style="max-width:90%" alt="Implementing automatic carousel carousel effects based on jQuery_jquery" ></li>
  </ul>
  <div class = "poster-btn poster-prev-btn"></div>
  <div class = "poster-btn poster-next-btn"></div>
 </div>
 
 </article>
 
 <script>window.jQuery || document.write('<script src="js/jquery-2.1.1.min.js"><\/script>')</script>
 <script src="js/jquery.carousel.js"></script>
 <script>
 Caroursel.init($('.caroursel'))
 </script>
</body>
</html>
I share with you the jQuery automatic carousel effect code. I hope you can like it and apply it in practice.

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
Behind the Scenes: What Language Powers JavaScript?Behind the Scenes: What Language Powers JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Is JavaScript Written in C? Examining the EvidenceIs JavaScript Written in C? Examining the EvidenceApr 25, 2025 am 12:15 AM

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript's Role: Making the Web Interactive and DynamicJavaScript's Role: Making the Web Interactive and DynamicApr 24, 2025 am 12:12 AM

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C   and JavaScript: The Connection ExplainedC and JavaScript: The Connection ExplainedApr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),