English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Carousel and Custom Scrollbar Combined with Mouse Wheel Sharing Code Snippet

This is a carousel I made myself, you can take a look, I haven't optimized it yet. Any suggestions for improvement can be discussed privately

You figure out the layout yourself

<div class="slider" id="circle">
<a href=""><img src="img}}/6p.jpg" alt="" /></a>
`
<ul class="circle" >
<li onclick="lun(1)" id="ico1">1</li>
<li onclick="lun(2)" id="ico2">2</li>
<li onclick="lun(3)" id="ico3">3</li>
<li onclick="lun(4)" id="ico4">4</li>
<li onclick="lun(5)" id="ico5">5</li>
<li class="current" onclick="lun(6)" id="ico6">6</li>
</ul>
<div class="arrow">
<a href="javaScript:;" class="arrow-l" onclick="bo2()" id="bo1"><</a>
<a href="javaScript:;" class="arrow-r" onclick="bo1()" id="bo2">></a>
</div>
</div>
<script>
var c = 0 ;
var t ;
window.onload = function () {
t = setInterval("bo1()",5000);
}
function lun(num){
c = num ;
var ptn = document.getElementById("circle").getElementsByTagName("img")[0];
for (var i = 1 ; i < 7;i++ ) {
var li = document.getElementById("circle").getElementsByTagName("li")[i-1];
li.style.backgroundColor = "#3E3E3E";
if (num == i) {
ptn.src = "img/"+ i + "p.jpg";
li.style.backgroundColor = "#B61B1F";
}
}
}
function bo1() {
if(c>=6{
c = 0 ;
}
c++;
lun(c);
}
function bo2() {
if(c<=1{
c = 7 ;
}
c--;
lun(c);
}
</script>

Let's see the custom scrollbar combined with mouse wheel DEMO below

The specific code is shown as follows:

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8-8"/>
<link href="css/reset.css" rel="stylesheet" type="text/css">/css">
<style type="text/css">/css">
body
{
font-size: 14px;
font-family: Microsoft YaHei, Tahoma, Geneva, sans-serif-serif;
background: #111;
}
#content ul
{
width: 960px;
margin: 150px auto;
padding: 60px 0;
}
#content ul li
{
margin-right: 20px;
width: 225px;
height: 180px;
float: left;
}
#content ul li:last-child
{
margin-right: 0;
}
#content ul li a
{
position: relative;
display: block;
width: 100%;
height: 100%;
/*stage (the parent container of the animation element) perspective*/
-webkit-perspective: 800px;
-moz-perspective: 800px;
}
#content ul li a > div
{
position: absolute;
left: 0;
height: 0;
width: 100%;
height: 100%;
color: #fff;
/*transform of the animation element-style*/
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-webkit-transition: .8s ease-in-out ;
-moz-transition: .8s ease-in-out ;
/*set the back of the animation element to hidden*/
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
}
#content ul li a div:first-child
{
/*
rotate around the y-axis
*/
-webkit-transform: rotateY(0);
-moz-transform: rotateY(0);
z-index: 2;
}
#content ul li a div:last-child
{
background: url("images/bg.jpg") no-repeat 0 0;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
z-index: 1;
}
#content ul li a:hover div:first-child
{
-webkit-transform: rotateY(-180deg);
-moz-transform: rotateY(-180deg);
}
#content ul li a:hover div:last-child
{
-webkit-transform: rotateY(0);
-moz-transform: rotateY(0);
}
#content ul li a div h3
{
margin: 0 auto 15px;
padding: 15px 0;
width: 200px;
height: 16px;
line-height: 16px;
font-size: 14px;
text-align: center;
border-bottom: 1px #fff dashed;
}
#content ul li a div p
{
padding: 0 10px;
font-size: 12px;
text-indent: 2em;
line-height: 18px;
}
</style>
</head>
<body>
<div id="content">
<ul>
<li>
<a href="#" target="_blank">
<div><img alt="" src="images/1.jpg"/></div>
<div>
<h3>Uzumaki Naruto</h3>
<p>The male protagonist in the Japanese manga "Naruto" by Kishimoto Masashi. Because he is sealed with the evil nine-tailed fox, he has suffered cold eyes and discrimination from the villagers. He is determined to become the sixth Hokage and gain everyone's recognition of his existence.</p>
</div>
</a>
</li>
<li>
<a href="#" target="_blank">
<div>
<img alt="" src="images/2.jpg"/>
</div>
<div>
<h3>Uchiha Hinata</h3>
<p>
in the work of the Japanese manga artist Kishimoto Masashi, "Naruto" is a male protagonist.3is the female protagonist. She is a female ninja from the Konoha Ninja Village, the eldest daughter of the head of the Hyuuga clan, a famous family in Konoha. She likes Uzumaki Naruto, and originally was a weak girl, but gradually became strong under Naruto's influence and grew into an outstanding ninja.</p>
</div>
</a>
</li>
<li>
<a href="#" target="_blank">
<div><img alt="" src="images/3.jpg"/></div>
<div>
<h3>Monkey D. Luffy</h3>
<p>Monkey D. Luffy is the main character of the popular Japanese anime "One Piece". He is the captain of the Straw Hat Pirates, dreaming of finding the legendary treasure - ONE PIECE, and becoming the Pirate King.</p>
</div>
</a>
</li>
<li>
<a href="#" target="_blank">
<div>
<img alt="" src="images/4.jpg"/>
</div>
<div>
<h3>Box Master</h3>
<p>
Danbo is a cute toy made of discarded cardboard boxes. With round eyes and a triangular mouth, it always exposes an innocent expression, making people feel soft-hearted. Danbo is a pure and kind little creature, and in its simple fantasy world, it always exudes the most sincere and lovable charm.</p>
</div>
</a>
</li>
</ul>
</div>
</body>
</html>

The above-mentioned are the JavaScript carousel and custom scrollbar code snippets shared with the mouse wheel, hoping it will be helpful to everyone. If you have any questions, please leave a message, and I will reply to you in time. I would also like to express my heartfelt thanks to everyone for their support of the Yelling Tutorial website!

You May Also Like