WATCH THE YOUTUBE PREVIEW:
MOVING SLIDER:
The moving slider contains two divs. The first div displays the full image and the second one has the selection tabs. On clicking them our display image moves to the specified image.
HTML:
<div id="main">
<div id="show">
<img src="a1.jpg">
<img src="a2.jpg">
<img src="a3.jpg">
<img src="a4.jpg">
</div>
<div id="select">
<div class="item">
<a href="#" onclick="allot(1);">
<img src="a1.jpg" alt="">
</a>
</div>
<div class="item">
<a href="#" onclick="allot(2);">
<img src="a2.jpg" alt="">
</a>
</div>
<div class="item">
<a href="#" onclick="allot(3);">
<img src="a3.jpg" alt="">
</a>
</div>
<div class="item">
<a href="#"onclick="allot(4);">
<img src="a4.jpg" alt="" >
</a>
</div>
</div>
</div>
CSS:
body{
background-image: linear-gradient(to right,red,orange);
}
img{
width: 100%;
}
#main{
width: 30%;
overflow: hidden;
position: absolute;
left: 480px;
top: 73px;
border: solid red;
box-shadow: 10px 5px 10px 4px black;
}
#show{
width: 100%;
display: flex;
transition: 0.5s all ease-in-out;
height: 60vh;
}
#select{
display: flex;
}
.item{
margin: 0.3rem;
margin-right: 0rem;
}
.item:hover{
border: solid white;
}
JAVASCRIPT:
var imid = 1;
const wid = document.querySelector("#show img:first-child").clientWidth;
var i;
function allot (i){
imid = i;
slide();
}
function slide(){
const wid = document.querySelector("#show img:first-child").clientWidth;
var dis = -(imid-1)*wid;
document.querySelector("#show").style.transform = `translateX(${dis}px)`;
}
The display image div contains two divs with the same dimensions and which fixes them. When we click on the image in select div a particular position number is allocated to them using allot function and further this accounts for the slide function which translates the display div to opposite direction of the product of position number and width of first image in display.
Comments
Post a Comment