Skip to content

Instantly share code, notes, and snippets.

@LocatelliPaolo
Created December 22, 2016 12:44
Show Gist options
  • Save LocatelliPaolo/cb35cc4fefff4244f58e051795decd2a to your computer and use it in GitHub Desktop.
Save LocatelliPaolo/cb35cc4fefff4244f58e051795decd2a to your computer and use it in GitHub Desktop.
Slider css + js
<!DOCTYPE html>
<html>
<head>
<title>SLIDER</title>
<link href="style.css" rel="stylesheet" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="slider.js"></script>
</head>
<body>
<div class="container-slider">
<div id="minus" class="arrow-minus">&#10094;</div>
<div id="plus" class="arrow-plus">&#10095;</div>
<div class="photos">
<img class="img-photos slider-active" src="IMMAGINI/foto-1.jpg"></img>
</div>
<div class="photos">
<img class="img-photos" src="IMMAGINI/foto-2.jpg"></img>
</div>
<div class="photos">
<img class="img-photos" src="IMMAGINI/foto-3.jpg"></img>
</div>
<div class="photos">
<img class="img-photos" src="IMMAGINI/foto-4.jpg"></img>
</div>
<div class="photos">
<img class="img-photos" src="IMMAGINI/foto-5.jpg"></img>
</div>
</div>
</body>
</html>
$(document).ready(function() {
$num = $(".photos").length-1;
$active = 0;
$("#plus").click(function() {
$active++;
if($active>$num)
{
$active = 0;
$(".slider-active").removeClass("slider-active");
$(".container-slider .photos:eq("+$active+") .img-photos").addClass("slider-active");
}
else
{
$(".slider-active").removeClass("slider-active");
$(".container-slider .photos:eq("+$active+") .img-photos").addClass("slider-active");
}
});
$("#minus").click(function() {
$active--;
if($active<0)
{
$active = $num;
$(".slider-active").removeClass("slider-active");
$(".container-slider .photos:eq("+$active+") .img-photos").addClass("slider-active");
}
else
{
$(".slider-active").removeClass("slider-active");
$(".container-slider .photos:eq("+$active+") .img-photos").addClass("slider-active");
}
});
});
body{
margin:0px;
font-family: Calibri, Candara, Segoe, 'Segoe UI', Optima, Arial, sans-serif;
}
.container-slider{
width:800px;
height:600px;
position:absolute;
border-radius:5px;
top:100px;
left:50%;
margin-left:-400px;
}
.photos{
width:800px;
height:600px;
position:absolute;
}
.img-photos{
width:100%;
height:100%;
position:absolute;
opacity:0;
-webkit-transition: opacity 500ms, -ms-transform 500ms, -webkit-transform 500ms, transform 500ms;
-moz-transition: opacity 500ms, -ms-transform 500ms, -webkit-transform 500ms, transform 500ms;
-o-transition: opacity 500ms, -ms-transform 500ms, -webkit-transform 500ms, transform 500ms;
transition: opacity 500ms, -ms-transform 500ms, -webkit-transform 500ms, transform 500ms;
}
.slider-active{
opacity:1;
-webkit-transition: opacity 500ms, -ms-transform 500ms, -webkit-transform 500ms, transform 500ms;
-moz-transition: opacity 500ms, -ms-transform 500ms, -webkit-transform 500ms, transform 500ms;
-o-transition: opacity 500ms, -ms-transform 500ms, -webkit-transform 500ms, transform 500ms;
transition: opacity 500ms, -ms-transform 500ms, -webkit-transform 500ms, transform 500ms;
}
.arrow-plus{
height:40px;
width:40px;
position:absolute;
left:100%;
top:50%;
margin-top:-20px;
margin-left:-50px;
z-index:100;
text-align:center;
font-size:24px;
line-height:40px;
color:#FFFFFF;
cursor:pointer;
border-radius:40px;
background-color:#000000;
}
.arrow-minus{
height:40px;
width:40px;
position:absolute;
z-index:100;
left:0%;
top:50%;
margin-top:-20px;
margin-left:10px;
text-align:center;
font-size:24px;
line-height:40px;
color:#FFFFFF;
cursor:pointer;
border-radius:40px;
background-color:#000000;
}
@media screen and (max-width: 900px) {
.container-slider{
width:600px;
height:450px;
margin-left:-300px;
}
.photos{
width:600px;
height:450px;
}
}
@media screen and (max-width: 650px) {
.container-slider{
width:400px;
height:300px;
margin-left:-200px;
}
.photos{
width:400px;
height:300px;
}
}
@media screen and (max-width: 450px) {
.container-slider{
width:300px;
height:200px;
margin-left:-150px;
}
.photos{
width:300px;
height:200px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment