Slider touch
How do I make an slider touch?
What is a slider touch? How do you make a slider touch? This script and codes were developed by Leo on 16 October 2022, Sunday.
Slider touch - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Slider touch</title> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="items"> <div class="item"> <div class="item-content"></div> </div> <div class="item"> <div class="item-content"> </div> </div> <div class="item"> <div class="item-content"> </div> </div> <div class="item"> <div class="item-content"> </div> </div> <div class="item"> <div class="item-content"></div> </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 touch - Script Codes CSS Codes
html,
body { margin: 0; padding: 0; height: 100%; background: #291545; overflow: hidden;
}
.items { position: absolute; margin: auto; top: 0; bottom: 0; width: 100%; height: 70%; padding-left: 1em; overflow: hidden;
}
.item { display: inline-block; float: left; height: 100%; width: 100%; cursor: -webkit-grab; cursor: grab; -webkit-transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1); transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1);
}
.item-content { height: 100%; width: 80%; background: #9C71EB; border-radius: 0.2em;
}
Slider touch - Script Codes JS Codes
(function() { var dragDistance, dragEnd, dragMove, dragStart, dragStartPoint, dragging, itemCurrent, itemTranslate, itemTranslateX, movePoint, resizeContainer, swapThreshold; itemCurrent = 0; itemTranslateX = 0; dragging = false; dragStartPoint = void 0; dragDistance = void 0; swapThreshold = 100; movePoint = void 0; /* * Resize responsively the slider */ resizeContainer = function() { var itemCount, itemWidth; itemCount = $(".items").children().length; itemWidth = $(window).width() * 0.8; $(".item").width(itemWidth); return $(".items").width(itemCount * itemWidth); }; /* * Resize responsively the slider */ itemTranslate = function(index) { var itemMargin, itemWidth, itemsTranslateX; console.log("Translate to " + index); itemWidth = $(".item").outerWidth(); if (index === 0) { return itemMargin = 0; } else { itemMargin = $(".item").outerWidth() - $(".item-content").outerWidth(); itemsTranslateX = (itemWidth * index) - (itemMargin * 2); console.log(itemsTranslateX); return $(".item").css({ "-webkit-transform": "translateX(-" + itemsTranslateX + "px)", "-ms-transform": "translateX(-" + itemsTranslateX + "px)", "transform": "translateX(-" + itemsTranslateX + "px)" }); } }; /* * Drag translation */ dragStart = function(e) { e.preventDefault(); dragging = true; return dragStartPoint = e.pageX; }; dragMove = function(e) { if (dragging) { movePoint = e.pageX; return dragDistance = movePoint - dragStartPoint; } }; dragEnd = function(e) { e.preventDefault(); if (Math.abs(dragDistance) > swapThreshold) { if (dragDistance > 0) { itemCurrent = itemCurrent - 1; } if (dragDistance < 0) { itemCurrent = itemCurrent + 1; } itemTranslate(itemCurrent); } return dragging = false; }; $(".item").on("touchstart mousedown", dragStart); $(".item").on('touchmove mousemove', dragMove); $(".item").on("touchend mouseup", dragEnd); $(window).resize(function() { return resizeContainer(); }); resizeContainer();
}).call(this);
Developer | Leo |
Username | leonard |
Uploaded | October 16, 2022 |
Rating | 3 |
Size | 3,795 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 |
Round circle loader | 2,248 Kb |
Circle wave loader | 2,192 Kb |
Photo selector with bounce animation | 3,366 Kb |
Phyramid.com loader | 3,128 Kb |
Drop up mobile menu animation | 3,516 Kb |
Strings | 2,109 Kb |
Pick a card | 5,642 Kb |
Triangle | 1,796 Kb |
Mouse scroll | 1,860 Kb |
Animation trails | 2,553 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 |
Sony Xperia Z3 Flat MockUp | Dapinitial | 4,379 Kb |
A bit of elegance | Hackthevoid | 9,095 Kb |
A Pen by James Podles | Jpod | 2,656 Kb |
A Different Type of Gallery | DonPage | 2,950 Kb |
Fading gradient button | Insprd | 1,713 Kb |
Realistic Buttons | Stoypenny | 2,248 Kb |
A Pen by Alex Edwards | Exards | 8,218 Kb |
Comment Jquery | SquishyAndroid | 2,421 Kb |
Practice using Wixel | Emnk | 3,057 Kb |
Spinners using Font Icons | Keyamoon | 3,007 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!