全屏轮播图
轮播图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
@charset "utf-8" ;#Slider { background-color : #333 ; color : #fff ; line-height : 27px ; position : relative; overflow : hidden; height : 80vh ; width : 100vw ; box-sizing : border-box; } h1 { font-weight : 700 ; font-size : 16px ; } .sContent p { text-indent : 2rem ; } .buttons { width : 100% ; } .slider { position : absolute; top : 0 ; left : 0 ; width : 100% ; height : 100% ; opacity : 0 ; transition : opacity .4s ease-in-out; } .current { opacity : 1 ; } #prev ,#next { position : absolute; top : 50% ; transform : translateY (-50% ); width : 50px ; height : 50px ; background-color : rgb (221 , 101 , 101 ); border : 2px solid rgb (255 , 255 , 255 ); border-radius : 50% ; padding : 2px ; color : #fff ; cursor : pointer; } #prev { left : 50px ; top : 40vh ; } #next { position : absolute; right : 50px ; top : 40vh ; transform : rotate (-180deg ); } #next :hover ,#prev :hover { background-color : #ccc ; color : #333 ; } #prev img ,#next img { position : absolute; left : 50% ; top : 20px ; transform : translate (-50% , 0 ); width : 16px ; } .slider :nth-child (1 ) { background : url ('../access/img/Slider/01.jpg' ) no-repeat center center/cover; } .slider :nth-child (2 ) { background : url ('../access/img/Slider/02.jpg' ) no-repeat center center/cover; } .slider :nth-child (3 ) { background : url ('../access/img/Slider/03.jpg' ) no-repeat center center/cover; } .slider :nth-child (4 ) { background : url ('../access/img/Slider/04.jpg' ) no-repeat center center/cover; } .slider :nth-child (5 ) { background : url ('../access/img/Slider/01.jpg' ) no-repeat center center/cover; } .slider .sContent { position : absolute; bottom : 50px ; right : 600px ; width : 600px ; color : #333 ; background-color : rgba (255 , 255 , 255 , .8 ); padding : 35px ; height : 120px ; opacity : 0 ; border-radius : 6px ; overflow : hidden; } .slider .current .sContent { opacity : 1 ; transform : translateX (600px ); transition : all 0.7s ease-in-out 0.3s ; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<div id ="Slider" > <div class ="slider current" > <div class ="sContent" > <h1 > 第一页</h1 > <p > 1924 年,安特生 (瑞典地质学家兼考古学家) 在甘肃临洮马家窑村发现一处远古文化遗址, 定名为仰韶文化马家窑期,在当地收集了大量的代表华夏文化的彩陶器皿。个沉寂几千年的远古文化, 第一次以马家窑期之名出现在世人面前! </p > </div > </div > <div class ="slider" > <div class ="sContent" > <h1 > 第二页</h1 > <p > 1924 年,安特生 (瑞典地质学家兼考古学家) 在甘肃临洮马家窑村发现一处远古文化遗址, 定名为仰韶文化马家窑期,在当地收集了大量的代表华夏文化的彩陶器皿。个沉寂几千年的远古文化, 第一次以马家窑期之名出现在世人面前! </p > </div > </div > ··· </div >
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
console .log ("正在加载 Slider.js·········" );const sliders = document .querySelectorAll (".slider" );const prev = document .querySelector ("#prev" );const next = document .querySelector ("#next" );const nextSlider = function ( ) { const current = document .querySelector (".current" ); if (current.nextElementSibling ) { current.nextElementSibling .classList .add ("current" ); } else { sliders[0 ].classList .add ("current" ); } setTimeout (() => current.classList .remove ("current" )); }; const prevSlider = function ( ) { const current = document .querySelector (".current" ); if (current.previousElementSibling ) { current.previousElementSibling .classList .add ("current" ); } else { sliders[sliders.length - 1 ].classList .add ("current" ); } setTimeout (() => current.classList .remove ("current" )); }; next.addEventListener ("click" , function ( ) { nextSlider (); }); prev.addEventListener ("click" , function ( ) { prevSlider (); }); var timer = setInterval (function ( ) { nextSlider (); }, 2000 ); var rmTimer = document .querySelector ("#Slider " );rmTimer.addEventListener ("mouseenter" , function ( ) { clearInterval (timer); timer = null ; console .log ("鼠标移入, 清除定时器···" ); }); rmTimer.addEventListener ("mouseleave" , function ( ) { timer = setInterval (function ( ) { nextSlider (); }, 2000 ); console .log ("鼠标移入, 开启定时器···" ); });
轮播图总结:
内容来源依据: https://www.bilibili.com/video/BV1LV411z72g?p=22