jQuery plugin to achieve carousel effect

jQuery plugin to achieve carousel effect

A jQuery plugin every day - jQuery plugin to implement a carousel chart, for your reference, the specific content is as follows

The effect is as follows

Code section

.rel{
 white-space:nowrap;
 overflow-y: hidden;
 overflow-x: auto;
}
.rel::-webkit-scrollbar{
 height: 0px;
 width: 0px;
}
.img{
 width: 100%;
 height: 100%;
}
<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Make another carousel</title>
  <script src="js/jquery-3.4.1.min.js"></script>
  <script src="js/zzlbt.js"></script>
  <link href="css/zzlbt.css" rel="stylesheet" type="text/css" />
  <style>
   *{
    margin: 0px;
    padding: 0px;
   }
   #div{
    position: fixed;
    top: 20px;
    left: 20px;
    width: 400px;
    height: 200px;
    border: 1px solid lightgray;
   }
   .div{
    width: 400px;
    height: 200px;
    float: left;
    margin: 10px;
   }
  </style>
 </head>
 <body>
  <div class="div"></div>
  <div class="div"></div>
 </body>
</html>
<script>
 $(function(){
  $(".div").lbt({
   data:[
    "img/1.png",
    "img/2.png",
    "img/3.png",
    "img/4.png"
   ]
  })
 })
</script>
$.prototype.lbt = function(obj) {
 obj = obj == undefined ? {} : obj;
 obj.time = obj.time==undefined?1000:obj.time;
 var that = this;
 var $that = $(this);
 $that.arr().forEach($item=>{
  $item.addClass("rel");
  $(function(){
   //Add dom
   obj.data.forEach(item=>{
    var $img = $("<img class='img' src='"+item+"' />");
    $img.appendTo($item);
   })
   //Execute the carousel var index = 0;
   var timer = setInterval(function(){
    $item.stop().animate({
     'scrollLeft':$item.width()*index+'px'
    },500)
    index = (index+1)%obj.data.length;
   },obj.time)
   //Some basic events, when the mouse hovers, the carousel and the axis below are paused})
  
 })
}
$.prototype.arr = function() {
 var that = this;
 var arr = [];
 for (var i = 0; i < that.length; i++) {
  var $dom = $(that[i]);
  arr.push($dom);
 }
 return arr;
}

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 implements carousel map detailed explanation and example code
  • Using jQuery to write left and right carousel effects
  • jQuery implements seamless left and right carousel
  • jQuery plugin slides to achieve seamless carousel effects
  • jQuery implements carousel chart and its principle detailed explanation
  • jQuery adaptive carousel plug-in Swiper usage example
  • jQuery implements left and right sliding carousel
  • JQuery and html+css to achieve a carousel with small dots and left and right buttons
  • Simple carousel function implemented by jQuery [suitable for beginners]

<<:  How to upload and download files between Linux server and Windows system

>>:  mysql workbench installation and configuration tutorial under centOS

Recommend

js implements array flattening

Table of contents How to flatten an array 1. Usin...

HTML Tutorial: HTML horizontal line segment

<br />This tag can display a horizontal line...

Creating a Secondary Menu Using JavaScript

This article example shares the specific code of ...

Linux Centos8 Create CA Certificate Tutorial

Install Required Files Yum install openssl-* -y C...

Detailed steps to install Mysql5.7.19 using yum on Centos7

There is no mysql by default in the yum source of...

Steps to install MySQL 8.0.23 under Centos7 (beginner level)

First, let me briefly introduce what MySQL is; In...

Detailed tutorial for installing MySQL on Linux

MySQL downloads for all platforms are available a...

Mini Program to Implement Slider Effect

This article example shares the specific code for...

Implementing a simple timer based on Vue method

Vue's simple timer is for your reference. The...

jQuery custom magnifying glass effect

This article example shares the specific code of ...

Understand the initial use of redux in react in one article

Redux is a data state management plug-in. When us...

Perfect solution to Docker Alpine image time zone problem

Recently, when I was using Docker to deploy a Jav...

Simple tutorial on using Navicat For MySQL

recommend: Navicat for MySQL 15 Registration and ...

CSS implements the bottom tapbar function

Now many mobile phones have the function of switc...