Slider touch

Developer
Size
3,795 Kb
Views
12,144

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 Previews

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);
Slider touch - Script Codes
Slider touch - Script Codes
Home Page Home
Developer Leo
Username leonard
Uploaded October 16, 2022
Rating 3
Size 3,795 Kb
Views 12,144
Do you need developer help for Slider touch?

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!

Leo (leonard) Script Codes
Create amazing blog posts 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!