Seamless carousel is a very common effect, and it is very simple once you understand the logic. The effect is as followsCode section<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Make seamless carousel</title> <script src="js/jquery-3.4.1.min.js"></script> <style> * { margin: 0; padding: 0; user-select: none; } #div { border: 1px solid lightgray; width: 600px; height: 300px; margin: 20px; overflow: hidden; } .item { border: 1px solid lightgray; width: 96%; height: 50px; margin: 10px auto; } </style> </head> <body> <div id="div"> <div class="rollbox"></div> </div> </body> </html> <script> $(document).ready(function() { for (var i = 0; i < 7; i++) { var $item = $("<div class='item'>" + i+ "</div>"); $item.appendTo($("#div .rollbox")); } }) //Carousel action$(function() { $("#div").roll(1); }) $.prototype.roll = function(span) { span = span == undefined ? 20 : span; //Scroll rate var $that = $(this).find('.rollbox'); var index = 0; var t = setInterval(function() { $that.css('margin-top', index + 'px'); index--; check(); }, span) // $that.mouseenter(function() { clearInterval(t); }) $that.mouseleave(function() { t = setInterval(function() { $that.css('margin-top', index + 'px'); index--; check(); }, span) }) function check(){ var first = $that.children().first(); var top = parseInt(first.css('margin-top').replace('px','')); var bottom = parseInt(first.css('margin-bottom').replace('px','')); var height =first.height(); bw = parseInt(first.css('border-width').replace('px','')); var temp = index+top+height+bottom; if(temp==top-2*bw){ var last = $that.children().last(); last.after(first); $that.css('margin-top','0px'); index=0; } } } </script> Explanation of ideas
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:
|
<<: Zabbix uses PSK shared key to encrypt communication between Server and Agent
>>: Analysis of MySQL's method of exporting to Excel
1. Experimental description In the virtual machin...
Some people say that doing advertising is like bei...
Kubernetes supports three types of authentication...
Look at the code first #/bin/sh datename=$(date +...
Table of contents 1. Use the withRouter component...
Table of contents 1. Introduction 2. Detailed exp...
As shown below: Yesterday: UNIX_TIMESTAMP(CAST(SY...
The select element creates a single-select or mult...
This article shares the specific code for WeChat ...
Step 1: Configure environment variables (my decom...
1. Call the parent component method directly thro...
Table of contents JavaScript Objects 1. Definitio...
Syn attack is the most common and most easily exp...
1. Set firewall rules Example 1: Expose port 8080...
1. Download MySQL from the official website: This...