index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script src="1.js" defer></script>
</head>
<body>
<div id="slider">
<div id="polosa">
<img src="images/hulk.png" alt="">
<img src="images/im.png" alt="">
<img src="images/im2.png" alt="">
<img src="images/kitty.png" alt="">
<img src="images/leo.png" alt="">
<img src="images/mt.png" alt="">
<img src="images/thor.png" alt="">
</div>
</div>
<button id="slider-left">Прокрутка</button>
</body>
</html>
style.css
#slider {
width: 384px;
height: 128px;
border: 5px solid black;
margin: 50px auto;
overflow: hidden;
}
#polosa {
width: 896px;
position: relative;
left: 0;
transition: all ease 1s;
}
#polosa img {
float: left;
}
#polosa::after {
content: "";
display: block;
clear: both;
}
1.js
document.getElementById('slider-left').onclick = sliderLeft;
var left = 0;
function sliderLeft() {
var polosa = document.getElementById('polosa');
left = left - 128;
if(left < -512) {
left = 0;
}
polosa.style.left = left+'px';
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<script src="1.js" defer></script>
</head>
<body>
<div id="slider">
<div id="polosa">
<img src="images/hulk.png" alt="">
<img src="images/im.png" alt="">
<img src="images/im2.png" alt="">
<img src="images/kitty.png" alt="">
<img src="images/leo.png" alt="">
<img src="images/mt.png" alt="">
<img src="images/thor.png" alt="">
</div>
</div>
<button id="slider-left">Прокрутка</button>
</body>
</html>
style.css
#slider {
width: 384px;
height: 128px;
border: 5px solid black;
margin: 50px auto;
overflow: hidden;
}
#polosa {
width: 896px;
position: relative;
left: 0;
transition: all ease 1s;
}
#polosa img {
float: left;
}
#polosa::after {
content: "";
display: block;
clear: both;
}
1.js
document.getElementById('slider-left').onclick = sliderLeft;
var left = 0;
function sliderLeft() {
var polosa = document.getElementById('polosa');
left = left - 128;
if(left < -512) {
left = 0;
}
polosa.style.left = left+'px';
}
Комментариев нет:
Отправить комментарий