Slider, flickity

Developer
Size
3,037 Kb
Views
12,144

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 Previews

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"), {});
Slider, flickity - Script Codes
Slider, flickity - Script Codes
Home Page Home
Developer Berkin
Username berkin
Uploaded January 09, 2023
Rating 3
Size 3,037 Kb
Views 12,144
Do you need developer help for Slider, flickity?

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!

Berkin (berkin) Script Codes
Create amazing Facebook ads with AI!

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!