Slider, flickity
How do I make an slider, flickity?
What is a slider, flickity? How do you make a slider, flickity? This script and codes were developed by Berkin on 09 January 2023, Monday.
Slider, flickity - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>slider, flickity</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="slider-container js-slider" style="height: 200px;"> <div class="slider-cell"></div> <div class="slider-cell" style="left: 100%"></div> <div class="slider-cell" style="left: 200%"></div> <div class="slider-cell" style="left: 300%"></div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Slider, flickity - Script Codes CSS Codes
*,
:after,
:before { -webkit-box-sizing: border-box;
}
.slider-container { position: relative; overflow: hidden;
}
.slider { position: absolute; width: 100%; height: 100%;
}
.slider-cell { width: 100%; height: 200px; border: 1px solid #888; background: #CCC; position: absolute;
}
Slider, flickity - Script Codes JS Codes
var Slider = (function(document, window, undefined) { var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; function Slider(element, options) { this.view = element; this.$view = $(element); this.options = $.extend({}, this.constructor.defaults, options); this.init(); } Slider.prototype.init = function() { var container = document.createElement('div'); container.className = "slider"; container.style.webkitTransform = "translateX(0)"; this.container = container; this.x = 0; var cells = this.view.querySelectorAll(".slider-cell"); this.cells = []; for ( var i = 0, len = cells.length; i < len; i++ ) { this.cells.push(new Cell(cells[i])); this.container.appendChild(cells[i]); } this.selectedIndex = 0; this.view.appendChild(this.container); this.$view.on("mousedown", this.handleTouchStart.bind(this)); this.$view.on("mousemove", this.handleTouchMove.bind(this)); this.$view.on("mouseup", this.handleTouchEnd.bind(this)); }; Slider.prototype.handleTouchStart = function(e) { this._isTouched = true; this._isScrolling = undefined; this._dragStartX = this.x; this._touchstart = { x: e.type === 'touchstart' ? e.targetTouches[0].pageX : e.pageX, y: e.type === 'touchstart' ? e.targetTouches[0].pageY : e.pageY }; this._touchStartTime = new Date().getTime(); console.log(e); }; Slider.prototype.handleTouchMove = function(e) { if ( !this._isTouched ) { return; } this._previousX = this.x; this._previousTime = this._currentTime; var pageX = e.type === 'touchmove' ? e.targetTouches[0].pageX : e.pageX; var pageY = e.type === 'touchmove' ? e.targetTouches[0].pageY : e.pageY; if ( this._isScrolling === undefined ) { this._isScrolling = !!(this._isScrolling || Math.abs(pageY - this._touchstart.y) > Math.abs(pageX - this._touchstart.x)); } if ( this._isScrolling ) { this._isTouched = false; return; } this._moveX = pageX - this._touchstart.x; this.x = this._dragStartX + this._moveX; this.container.style.webkitTransform = "translateX(" + this.x + "px)"; this._currentTime = new Date().getTime(); }; Slider.prototype.update = function() { var self = this; this.x = this.x + this._velocity / ( 1 - this.getFrictionFactor() ); this.container.style.webkitTransform = "translateX(" + this.x + "px)"; console.log(this.restingPoint, this.x); if ( this.restingPoint < this.x ) { requestAnimationFrame(function() { self.update(); }) } }; Slider.prototype.getFrictionFactor = function() { return 1 - .5; }; Slider.prototype.handleTouchEnd = function(e) { this._isTouched = false; this._velocity = (this._previousX - this.x) / (this._previousTime - this._currentTime); this._velocity *= 1000/60; this.restingPoint = this.cells[this.selectedIndex+1].x; this.update(); }; Slider.defaults = { }; function Cell(element) { this.view = element; this.x = -700; } return Slider;
})(document, window);
new Slider(document.querySelector(".js-slider"), {});
Developer | Berkin |
Username | berkin |
Uploaded | January 09, 2023 |
Rating | 3 |
Size | 3,037 Kb |
Views | 12,144 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Merge overlapping intervals | 1,889 Kb |
Tether control | 15,630 Kb |
IOS style alphabetic scroll | 3,488 Kb |
Javascript - Merge Sort | 1,509 Kb |
Touch Carousel - last, no gaps. | 4,332 Kb |
Touch Carousel - First One | 3,901 Kb |
Javascript - Insertion Sort | 1,501 Kb |
Javascript - Selection Sort | 1,577 Kb |
Javascript - Bubble Sort | 1,533 Kb |
Simple carousel | 3,098 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Medium Menu | Lucasmotta | 3,923 Kb |
Resume | Rottingroom | 5,483 Kb |
Intake Form Page 2 | Ijantje | 4,983 Kb |
Loading animation with css | Icebob | 2,947 Kb |
Z-index demo | Kblh | 1,534 Kb |
Nice responsive team page | Infomiho | 3,139 Kb |
Responsive Menu I | Rodericksandoval | 3,045 Kb |
Wikipedia API | Coderpilot | 2,802 Kb |
A Pen by Mike Otis | Mikeotis | 3,185 Kb |
Bootstrap Carousel Fade Transition | Rowno | 2,484 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!