Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

slider dots css

<html>
<div class="center">

	<div class="slider" data-pos="0">
		<div class="slider__slides">
			<div class="slider__slide"></div>
			<div class="slider__slide"></div>
			<div class="slider__slide"></div>
			<div class="slider__slide"></div>
		</div>
		<div class="slider__dots">
			<a href="#" class="slider__indicator"></a>
			<a href="#" class="slider__dot" data-pos="0"></a>
			<a href="#" class="slider__dot" data-pos="1"></a>
			<a href="#" class="slider__dot" data-pos="2"></a>
			<a href="#" class="slider__dot" data-pos="3"></a>
		</div>
	</div>

</div>

</html> 

<style>
.slider {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.slider__slides {
  position: relative;
  width: 400%;
  height: 100%;
  transition: transform 0.3s cubic-bezier(0.51, 0.92, 0.24, 1);
  will-change: transform;
}
.slider[data-pos="0"] .slider__slides {
  transform: translateX(0%);
}
.slider[data-pos="1"] .slider__slides {
  transform: translateX(-25%);
}
.slider[data-pos="2"] .slider__slides {
  transform: translateX(-50%);
}
.slider[data-pos="3"] .slider__slides {
  transform: translateX(-75%);
}
.slider__slide {
  float: left;
  width: 25%;
  height: 100%;
}
.slider__dots {
  display: flex;
  position: absolute;
  bottom: 1.5em;
  left: 50%;
  transform: translateX(-50%);
}
.slider__dot, .slider__indicator {
  display: block;
  margin: 0 0.5em;
  width: 1em;
  height: 1em;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 100px;
}
.slider__indicator {
  position: absolute;
  background: white;
  width: auto;
}
.slider__indicator--left {
  transition: left 0.3s cubic-bezier(0.51, 0.92, 0.24, 1.15), right 0.3s 0.1s cubic-bezier(0.51, 0.92, 0.24, 1.15);
}
.slider__indicator--right {
  transition: left 0.3s 0.1s cubic-bezier(0.51, 0.92, 0.24, 1.15), right 0.3s cubic-bezier(0.51, 0.92, 0.24, 1.15);
}
.slider[data-pos="0"] .slider__indicator {
  left: 0em;
  right: 6em;
}
.slider[data-pos="1"] .slider__indicator {
  left: 2em;
  right: 4em;
}
.slider[data-pos="2"] .slider__indicator {
  left: 4em;
  right: 2em;
}
.slider[data-pos="3"] .slider__indicator {
  left: 6em;
  right: 0em;
}

.center {
  display: flex;
  height: 100vh;
  justify-content: center;
  align-items: center;
  background: #333;
}

.slider {
  max-width: 600px;
  max-height: 400px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}
.slider__slide:nth-child(1) {
  background: #309954;
}
.slider__slide:nth-child(2) {
  background: #ffbd3c;
}
.slider__slide:nth-child(3) {
  background: #f8593e;
}
.slider__slide:nth-child(4) {
  background: #4086fa;
}
</style>

<script> 
let dots = 4;
let sliderElem = document.querySelector(".slider");
let dotElems = sliderElem.querySelectorAll(".slider__dot");
let indicatorElem = sliderElem.querySelector(".slider__indicator");

Array.prototype.forEach.call(dotElems, (dotElem) => {
	dotElem.addEventListener("click", (e) => {
		let currentPos = parseInt(sliderElem.getAttribute("data-pos"));
		let newPos = parseInt(dotElem.getAttribute("data-pos"));

		let newDirection = newPos > currentPos ? "right" : "left";
		let currentDirection = newPos < currentPos ? "right" : "left";

		indicatorElem.classList.remove(`slider__indicator--${currentDirection}`);
		indicatorElem.classList.add(`slider__indicator--${newDirection}`);
		sliderElem.setAttribute("data-pos", newPos);
	});
});

</script>
Comment

PREVIOUS NEXT
Code Example
Typescript :: swift charts margins 
Typescript :: The softness of a spot lights edge is controlled by penumbra angle, value gives perfect hard edge: 
Typescript :: typescript nested array 
Typescript :: install djs typescript 
Typescript :: rstudio plots arrows(), text() 
Typescript :: nodejs transofrm method into promise method 
Typescript :: convert angle to 0-360 godot 
Typescript :: elements of programming interviews in python 
Typescript :: multi select + search + Multiselect and Search in angular 13 
Typescript :: mac book join raspberry pi webserver 
Typescript :: why my res.data returns array of objects ? (AngularJs) 
Typescript :: useHorizontalScroll react 
Typescript :: how to pass data between requests 
Typescript :: how to set value of multiselect dropdown for reactive forms in angular 6 
Typescript :: engineering adding requirements to password 
Typescript :: python fancy way to get arguments from the command line 
Typescript :: how to append different lists in installed apps django 
Typescript :: to move previous month 
Typescript :: Give an O (n lg k)-time algorithm to merge k sorted lists into one sorted list 
Typescript :: typescript annotation 
Typescript :: change css to scss in angular online 
Typescript :: typescript default value null or undefined 
Typescript :: typescript enum value to enum 
Typescript :: reflect-metadata 
Typescript :: How to separate two similar names from two lists in Python 
Cpp :: howt o initialize 3d vector in c++ 
Cpp :: c++ get filename from path 
Cpp :: vector with pinter cout c++ 
Cpp :: calculate time difference cpp 
Cpp :: remove all element of vector c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =