From f25c6c895fbfa5c5e81ac70bdf99c5e0c63a3c7b Mon Sep 17 00:00:00 2001 From: shorif Date: Tue, 29 Nov 2022 21:17:25 +0600 Subject: [PATCH] slider change without requesting for image --- .gitignore | 2 ++ package.json | 58 +++++++++++++++---------------- src/components/Slider.jsx | 41 +++++++++++----------- src/styles.scss | 72 +++++++++++++++++++++++---------------- 4 files changed, 94 insertions(+), 79 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..25c8fdb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json \ No newline at end of file diff --git a/package.json b/package.json index 2de441a..17289e5 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,30 @@ { - "name": "carousel2", - "version": "1.0.0", - "description": "", - "keywords": [], - "main": "src/index.js", - "dependencies": { - "react": "17.0.2", - "react-dom": "17.0.2", - "react-icons": "4.2.0", - "react-scripts": "4.0.0", - "sass": "1.34.0" - }, - "devDependencies": { - "@babel/runtime": "7.13.8", - "typescript": "4.1.3" - }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test --env=jsdom", - "eject": "react-scripts eject" - }, - "browserslist": [ - ">0.2%", - "not dead", - "not ie <= 11", - "not op_mini all" - ] -} \ No newline at end of file + "name": "carousel2", + "version": "1.0.0", + "description": "", + "keywords": [], + "main": "src/index.js", + "dependencies": { + "react": "17.0.2", + "react-dom": "17.0.2", + "react-icons": "4.2.0", + "react-scripts": "4.0.0", + "sass": "1.34.0" + }, + "devDependencies": { + "@babel/runtime": "7.13.8", + "typescript": "4.1.3" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test --env=jsdom", + "eject": "react-scripts eject" + }, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} diff --git a/src/components/Slider.jsx b/src/components/Slider.jsx index 446bfd4..5ef35e3 100644 --- a/src/components/Slider.jsx +++ b/src/components/Slider.jsx @@ -3,27 +3,28 @@ import { FaArrowAltCircleRight, FaArrowAltCircleLeft } from "react-icons/fa"; import { useState } from "react"; import data from "./SlideData"; const Slider = () => { - const [current, setCurrent] = useState(0); + const [current, setCurrent] = useState(0); - const nextSlide = () => { - setCurrent(current === data.length - 1 ? 0 : current + 1); - }; - const prevSlide = () => { - setCurrent(current === 0 ? data.length - 1 : current - 1); - }; + const nextSlide = () => { + setCurrent(current === data.length - 1 ? 0 : current + 1); + }; + const prevSlide = () => { + setCurrent(current === 0 ? data.length - 1 : current - 1); + }; - return ( -
- - - {data.map((d, index) => { - return current === index ? ( -
- images -
- ) : null; - })} -
- ); + return ( +
+ + + {data.map((d, index) => ( +
+ images +
+ ))} +
+ ); }; export default Slider; diff --git a/src/styles.scss b/src/styles.scss index b6b959d..40f917a 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -1,39 +1,51 @@ .App { - font-family: sans-serif; - text-align: center; + font-family: sans-serif; + text-align: center; } .slider { - position: relative; - height: 100vh; - width: 100%; - box-sizing: border-box; - display: flex; - justify-content: center; - align-items: center; - margin:0; - padding: 0; - + position: relative; + height: 60vh; + width: 100%; + box-sizing: border-box; + display: flex; + justify-content: center; + align-items: center; + margin: 0; + padding: 0; +} +.slide { + position: absolute; + width: 100%; + height: 100%; + min-width: 50%; + font-size: 50px; + opacity: 0; + pointer-events: none; + transform: scale(0.8); + transition: 0.5s ease-in-out; +} +.slide__active { + opacity: 1; + transform: scale(1); + pointer-events: visible; } -.slide{ - min-width: 50%; - height: 60vh;; - font-size: 50px; +img { + width: 100%; + height: 100%; + object-fit: cover; } -img{ - width: 100%; - height: 100%; - object-fit: contain; +.left-arrow, +.right-arrow { + position: absolute; + z-index: 1; + font-size: 30px; + top: 50%; + color: yellowgreen; } -.left-arrow,.right-arrow{ - position: absolute; - z-index: 1; - font-size: 30px; - top: 50%; +.left-arrow { + left: 5%; } -.left-arrow{ - left:5%; +.right-arrow { + right: 5%; } -.right-arrow{ - right:5% -} \ No newline at end of file