Evgeny 3 年之前
當前提交
869a57c534
共有 10 個文件被更改,包括 102 次插入0 次删除
  1. 0 0
      README.md
  2. 二進制
      images/cover.png
  3. 二進制
      images/elephant.png
  4. 二進制
      images/gorilla.png
  5. 二進制
      images/home.png
  6. 二進制
      images/ice_cream.png
  7. 二進制
      images/slider.png
  8. 28 0
      index.html
  9. 18 0
      script.js
  10. 56 0
      style.css

+ 0 - 0
README.md


二進制
images/cover.png


二進制
images/elephant.png


二進制
images/gorilla.png


二進制
images/home.png


二進制
images/ice_cream.png


二進制
images/slider.png


+ 28 - 0
index.html

@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Cлайдер</title>
+    <link rel="stylesheet" href="./style.css">
+</head>
+
+<body>
+    <div class="container">
+        <h1>Слайдер на js</h1>
+        <div class="slider">
+            <div class="slider-line">
+                <img src="./images/elephant.png" alt="">
+                <img src="./images/gorilla.png" alt="">
+                <img src="./images/home.png" alt="">
+                <img src="./images/ice_cream.png" alt="">
+            </div>
+        </div>
+        <button class="slider-prev">Prev</button>
+        <button class="slider-next">Next</button>
+    </div>
+    <script src="script.js"></script>
+</body>
+
+</html>

+ 18 - 0
script.js

@@ -0,0 +1,18 @@
+let offset = 0;
+const sliderLine = document.querySelector('.slider-line');
+
+document.querySelector('.slider-next').addEventListener('click', function(){
+    offset = offset + 256;
+    if (offset > 768) {
+        offset = 0;
+    }
+    sliderLine.style.left = -offset + 'px';
+});
+
+document.querySelector('.slider-prev').addEventListener('click', function () {
+    offset = offset - 256;
+    if (offset < 0) {
+        offset = 768;
+    }
+    sliderLine.style.left = -offset + 'px';
+});

+ 56 - 0
style.css

@@ -0,0 +1,56 @@
+* {
+    margin: 0;
+}
+
+html, body {
+    font-size: 18px;
+    font-family: sans-serif;
+}
+
+.container {
+    max-width: 1200px;
+    margin: 30px auto;
+    background: #f1f1f1;
+    padding: 30px;
+}
+
+h1 {
+    text-align: center;
+    margin-bottom: 40px;
+}
+
+button {
+    background: none;
+    border: 1px solid black;
+    border-radius: 4px;
+    padding: 10px 20px;
+    font-size: .9rem;
+}
+
+button:hover {
+	background: orangered;
+	cursor: pointer;
+}
+
+button:active {
+    background: #000;
+    color: #fff;
+}
+
+.slider {
+    border: 2px solid black;
+    width: 256px;
+    height: 256px;
+    margin: 20px auto;
+    overflow: hidden;
+}
+
+.slider-line {
+    width: 1024px;
+    height: 256px;
+    display: flex;
+    background: orange;
+    position: relative;
+    left: 0;
+    transition: all ease 1s;
+}