The js seamless scrolling effect can be seen on almost any web page. Some may be plug-ins, but in fact, using original javascript is relatively simple.
The main thing is to use js location knowledge.
1.innerHTML: Set or get the html tag of the element
2.scrollLeft: Set or get the distance between the left boundary of the object and the leftmost end of the currently visible content in the window
3.offsetWidth: Set or get the width of the specified label
4.setInterval(): Set the method to start regularly
5.clearInterval(); Clear the timer
Reproduction image:
Sneak: demo
The code copy is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>javascript scroll production</title>
</head>
<body>
<style>
/*conment*/
*{
margin: 0;
padding: 0;
}
img{max-width: 100%;}
.container{
max-width: 620px;
margin: 0 auto;
padding-top: 50px;
}
.text-center{text-align: center;}
.list-inline li{
display: inline-block;
}
.hide{display: none;}
hr{
margin:20px 0;
}
.tag{
background-color: #ccc;
padding: 5px 0;
}
.tag li{
padding: 0 10px;
border-left: 1px solid #fff;
cursor:pointer;
}
.tag li:first-child{
border-left: transparent;
}
.tag li.active{
background-color: #ddd;
}
.scroll{
position: relative;
padding: 10px;
margin-bottom: 20px;
background-color: #ddd;
}
.wrap{
overflow: hidden;
}
.content{
min-width: 3000px;
height: 200px;
}
.content ul{
float: left;
}
.content ul li{
display: inline-block;
max-width: 200px;
}
#prev,#next{
width: 50px;
height: 50px;
margin-top: -25px;
background-color: #ccc;
line-height: 50px;
text-align: center;
cursor: pointer;
}
#prev{
position: absolute;
left: 0;
top:50%;
border-radius: 0 25px 25px 0;
}
#next{
position: absolute;
right: 0;
top:50%;
border-radius: 25px 0 0 25px;
}
</style>
<div>
<h1>Picture scrolling production</h1>
<hr>
<div>
<div id="wrap">
<div id="content" >
<ul id="list1">
<li> <img src="freelance.gif"> </li>
<li> <img src="button.gif"></li>
<li> <img src="load.gif"></li>
<li> <img src="straw.gif"></li>
</ul>
<ul id="list2">
</ul>
</div>
</div>
<div id="prev">
prev
</div>
<div id="next">
next
</div>
</div>
</div>
<script>
var wrap=document.getElementById('wrap');
var list1=document.getElementById('list1');
var list2=document.getElementById('list2');
var prev=document.getElementById('prev');
var next=document.getElementById('next');
//Create a copy of the content list
list2.innerHTML=list1.innerHTML;
//Change to the left
function scroll(){
if(wrap.scrollLeft>=list2.offsetWidth){
wrap.scrollLeft=0;
}
else{
wrap.scrollLeft++;
}
}
timer = setInterval(scroll,1);
// Use clearInterval() for mouse stay
wrap.onmouseover=function(){
clearInterval(timer);
}
wrap.onmouseout=function(){
timer = setInterval(scroll,1);
}
//Accelerate to the left
function scroll_l(){
if(wrap.scrollLeft>=list2.offsetWidth){
wrap.scrollLeft=0;
}
else{
wrap.scrollLeft++;
}
}
//Scroll to the right
function scroll_r(){
if(wrap.scrollLeft<=0){
wrap.scrollLeft+=list2.offsetWidth;
}
else{
wrap.scrollLeft--;
}
}
prev.onclick=function(){
clearInterval(timer);
change(0)
}
next.onclick=function(){
clearInterval(timer);
change(1)
}
function change(r){
if(r==0){
timer = setInterval(scroll_l,60);
wrap.onmouseout = function(){
timer = setInterval(scroll_l,60);
}
}
if(r==1){
timer = setInterval(scroll_r,60);
wrap.onmouseout = function(){
timer = setInterval(scroll_r,60);
}
}
}
</script>
</body>
Very concise and practical code, please beautify it according to your project needs.