Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                	<!DOCTYPE html>
	<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width = device-width, initial-scale = 1">
		<title></title>
		<link rel="stylesheet" type="text/css" href="slide.css">
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
	</head>
	<body>
		<div class="wraper">
			<div class="slides">
					<ul>
						<li style="background-image: url(https://images.wallpaperscraft.com/image/league_of_legends_poro_art_tongue_99916_1366x768.jpg">
						</li>
						<li style="background-image: url(https://images.wallpaperscraft.com/image/the_elder_scrolls_online_sword_of_the_night_warrior_assassin_95957_1366x768.jpg);">
						</li>
						<li class="hienlen" style="background-image: url(https://images.wallpaperscraft.com/image/league_of_legends_girl_face_art_108749_1366x768.jpg">
						</li>
						<li style="background-image: url(https://images.wallpaperscraft.com/image/league_of_legends_poro_teemo_105044_1366x768.jpg);">
						</li>
						<li style="background-image: url(https://images.wallpaperscraft.com/image/league_of_legends_malphite_art_107905_1366x768.jpg">
						</li>
						<div class="color" style="background-color:black; width: 100%; height: 100%">
				
						</div>
					</ul>
			</div>
			<div class="anhnho">
				<ul>
						<li style="background-image: url(https://images.wallpaperscraft.com/image/league_of_legends_poro_art_tongue_99916_1366x768.jpg">
						</li>
						<li style="background-image: url(https://images.wallpaperscraft.com/image/the_elder_scrolls_online_sword_of_the_night_warrior_assassin_95957_1366x768.jpg);">
						</li>
						<li class="duongvien" style="background-image: url(https://images.wallpaperscraft.com/image/league_of_legends_girl_face_art_108749_1366x768.jpg">
						</li>
						<li style="background-image: url(https://images.wallpaperscraft.com/image/league_of_legends_poro_teemo_105044_1366x768.jpg);">
						</li>
						<li style="background-image: url(https://images.wallpaperscraft.com/image/league_of_legends_malphite_art_107905_1366x768.jpg">
						</li>
					</ul>
			</div>
			<div class="nut">
				<ul>
					<li>
						<i class="far fa-caret-square-left"></i>
					</li>
					<li>
						<i class="far fa-caret-square-right"></i>
					</li>
				</ul>
			</div>
		</div>
		<script type="text/javascript" src="slide.js"></script>
	</body>
	</html>
              
            
!

CSS

              
                *{
	padding:0;
	margin:0;
	border:none;
}
html,body,.wraper,.slides,ul,li{
	width: 100%;
	height: 100%;
}
.wraper {
    position: relative;
    overflow:hidden;
}
.nut ul li i {
    font-size: 40px;
}

.slides ul li {
    position: absolute;
    background-size: cover;
}
.nut {
    position: absolute;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
}

.nut ul li {
    display: inline;
    cursor: pointer;
}
.nut ul li i{
	transition: 0.5s;
}
.nut ul li:hover i{
	color:white;
	transition: 0.5s;
}
.slides ul li{
	opacity: 0 ;
}
ul li.hienlen{
	opacity: 1; 
	transition: 0.5s;
}
/*Viet hieu ung ra vao cho cac slide*/
div.anhnho{
	width: 100%;
	height: 100%;
	position: absolute;
	top: 50px;
}
div.anhnho li{
	width: 7%;
	height: 7%;
	background-size: cover;

}
.duongvien{
	border: 3px solid white;
}
              
            
!

JS

              
                document.addEventListener("DOMContentLoaded",function(){
	//Truy xuất phần tử 2 nút trái phải và các slide
	var nut = document.querySelectorAll('div.nut ul li'),
		nuttrai = nut[0],
		nutphai = nut[1];
	var slides = document.querySelectorAll('div.slides ul li')
	// Tìm ra số phần tử cuối cùng vì là mảng nên chúng ta sẽ lấy độ dài của mảng - 1
	var cuoicung = slides.length - 1;
	//Khi click nút trái
	var anhnho = document.querySelectorAll('div.anhnho li');
	chuyenslide = function(){
		//1.Lấy vị trí slide hiện tại
		var vitrislideht = 0
		var slideht = document.querySelector('ul li.hienlen');
		var anhnhoht = document.querySelector('div.anhnho li');
		for(var i = 0; slideht = slideht.previousElementSibling; vitrislideht++){

		}// đã lấy được vị trí sau khi thực hiện vòng lặp for này.
		//2. Bỏ tất cả các class hienlen
		for(var i = 0; i < slides.length; i++){
			slides[i].classList.remove('hienlen');
			anhnho[i].classList.remove('duongvien');
		}
		//3.2 Khi slide chuyển đến 0 thì đặt vitrislide hien tại = vitricuoicung + 1 
		if(vitrislideht == 0){
			vitrislideht = cuoicung + 1;
			slides[vitrislideht-1].classList.add('hienlen');
			anhnho[vitrislideht-1].classList.add('duongvien');
		}
		else{
		//3.1 Chuyển sang slide phía sau 
		slides[vitrislideht-1].classList.add('hienlen');
		anhnho[vitrislideht-1].classList.add('duongvien');
		}

	}
	// Chỉ cần thực hiện 1 hàm r x2 lên thay đổi 1 tí là dc!!!
	chuyenslidep = function(){
		//1.Lấy vị trí slide hiện tại
		var vitrislideht = 0;
		var slideht = document.querySelector('ul li.hienlen');
		for(var i = 0; slideht = slideht.previousElementSibling; vitrislideht++){

		}// đã lấy được vị trí sau khi thực hiện vòng lặp for này.
		//2. Bỏ tất cả các class hienlen
		for(var i = 0; i < slides.length; i++){
			slides[i].classList.remove('hienlen');
			anhnho[i].classList.remove('duongvien');
		}
		if(vitrislideht == cuoicung){
			vitrislideht = -1;
		//ở đây mình k cần dùng else vì khi thực hiện xong lệnh if nó sẽ nhảy xuống thực hiện lệnh add class luôn. 
		}
		//3. Chuyển sang slide lên trước
		slides[vitrislideht+1].classList.add('hienlen');
		//4. Đến slide đầu tiên thì chuyển đến nó đến vị trí cuôi cùng.
		anhnho[vitrislideht+1].classList.add('duongvien');
	}

	nuttrai.addEventListener('click',chuyenslide);
	nutphai.addEventListener('click',chuyenslidep);
},false)
              
            
!
999px

Console