For supporting file is use in online link below :-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,600i&display=swap" rel="stylesheet">
HTML
<h1>Incredibly Basic Slider</h1>
<div id="slider">
<a href="#" class="control_next">></a>
<a href="#" class="control_prev"><</a>
<ul>
<li><img src="https://static1.squarespace.com/static/504247fb84ae39da43a5390b/54595a08e4b0915c5565d01c/5756da978259b50a3ba8f58e/1526768966631/japanese-garden-design-west-linn.jpg?format=500w"></li>
<li><img src="https://static1.squarespace.com/static/504247fb84ae39da43a5390b/t/5a12ee169140b7281e423f18/1511190116704/japanese-garden-landscaping-gresham.jpg?format=500w"></li>
<li><img src="https://i.guim.co.uk/img/media/9e930d722d08f22ca34ca5d3f9ba0c05759651cd/0_39_4288_2573/500.jpg?quality=85&auto=format&fit=max&s=cd65b0ee34c45ef5fd72a921af395137"></li>
<li><img src="https://i.guim.co.uk/img/media/cfb3af74aae4b8ad187d9ae625fe44057841bb0f/0_205_5667_3400/500.jpg?quality=85&auto=format&fit=max&s=198b0729ee338d18357c2399b69602a3"></li>
<li><img src="https://www.spiderlawns.com/files/account/images/home-trimming.jpg"></li>
</ul>
</div>
<ul class="thumbnail"></ul>
Css
-----------------
html {
border-top: 5px solid #fff;
background: #58DDAF;
color: #2a2a2a;
}
html, body {
margin: 0;
padding: 0;
font-family: 'Open Sans';
}
h1 {
color: #fff;
text-align: center;
font-weight: 300;
}
#slider {
position: relative;
overflow: hidden;
margin: 20px auto 0 auto;
border-radius: 4px;
width: 500px;
}
#slider ul {
position: relative;
margin: 0;
padding: 0;
list-style: none;
}
#slider ul li {
position: relative;
display: block;
float: left;
margin: 0;
padding: 0;
width: 500px;
height: 300px;
background: #ccc;
text-align: center;
line-height: 300px;
}
a.control_prev, a.control_next {
position: absolute;
top: 40%;
z-index: 999;
display: block;
padding: 4% 3%;
width: auto;
height: auto;
background: #2a2a2a;
color: #fff;
text-decoration: none;
font-weight: 600;
font-size: 18px;
opacity: 0.8;
cursor: pointer;
}
a.control_prev:hover, a.control_next:hover {
opacity: 1;
-webkit-transition: all 0.2s ease;
}
a.control_prev {
border-radius: 0 2px 2px 0;
}
a.control_next {
right: 0;
border-radius: 2px 0 0 2px;
}
.slider_option {
position: relative;
margin: 10px auto;
width: 160px;
font-size: 18px;
}
.thumbnail{
width: 500px;
margin: 0 auto;
list-style: none;
padding: 0px;
display: flex;
}
.thumbnail li{
flex-grow: 1;
padding: 5px;
cursor: pointer;
}
.thumbnail li img{
width: 100%;
height: auto;
}
js
------------------------------
<script>
jQuery(document).ready(function ($) {
var slideCount = $('#slider ul li').length;
var slideWidth = $('#slider ul li').width();
//var slideHeight = $('#slider ul li').height();
var sliderUlWidth = slideCount * slideWidth;
$('#slider ul').css({ width: sliderUlWidth});
var counter = 0;
function moveLeft() {
if(Math.abs(counter) != 0){
counter++
$('#slider ul').css({'transform': 'translate3d('+ slideWidth * counter+'px, 0px, 0px)', 'transition': 'all 0.25s ease 0s'})
}
};
function moveRight() {
if(Math.abs(counter) != slideCount - 1){
counter--
// console.log(counter);
$('#slider ul').css({'transform': 'translate3d('+ slideWidth * counter+'px, 0px, 0px)', 'transition': 'all 0.25s ease 0s'})
}
};
$("#slider ul li").each(function(){
var img_src = $(this).find("img").attr("src");
$(".thumbnail").append('<li><img src="'+ img_src +'"></li>');
})
$(".thumbnail li").click(function(){
var slide_index = $(this).index();
var slide_move = -slideWidth * slide_index;
$('#slider ul').css({'transform': 'translate3d('+ slide_move +'px, 0px, 0px)', 'transition': 'all 0.25s ease 0s'})
})
$('a.control_prev').click(function (e) {
e.preventDefault();
moveLeft();
});
$('a.control_next').click(function (e) {
e.preventDefault();
moveRight();
});
});
</script>
No comments:
Post a Comment