NgTouchSpin
How do I make an ngtouchspin?
购物车或价格Spin http://demo.jankuri.com/ngTouchSpin/ https://github.com/jkuri/ngTouchSpin. What is a ngtouchspin? How do you make a ngtouchspin? This script and codes were developed by Kevin on 28 August 2022, Sunday.
NgTouchSpin - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>ngTouchSpin</title> <link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'>
<link rel='stylesheet prefetch' href='http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div ng-controller="ngTouchSpinCtrl" class="spinWrapper"> <ng-touch-spin ng-model="ctrl.val" prefix="$" postfix="%" initval="26.20" decimals="2" step="0.5"> </ng-touch-spin> <input type="text" value="88" ng-model="ctrl.val2" prefix="$" ng-touch-spin> <input type="text" value="590" ng-model="ctrl.val3" min="580" max="600" ng-touch-spin> <input type="text" ng-model="ctrl.val4" ng-touch-spin>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
NgTouchSpin - Script Codes CSS Codes
.spinWrapper { width: 90%; margin: 0 auto; padding: 20px 10px;
}
.spinWrapper > * { margin-top: 10px;
}
NgTouchSpin - Script Codes JS Codes
angular.module('jkuri.touchspin', [])
.directive('ngTouchSpin', ['$timeout', '$interval', function($timeout, $interval) { 'use strict'; var setScopeValues = function(scope, attrs) { var defaultScope = { min: 0, max: 100, step: 1, prefix: undefined, postfix: undefined, decimals: 0, stepInterval: 500, stepIntervalDelay: 100, initval: '' }; angular.forEach(defaultScope, function(value, key){ scope[key] = attrs.hasOwnProperty(key) ? attrs[key] : value; }); scope['val'] = attrs.value || scope.initval; }; return { restrict: 'EA', require: '?ngModel', scope: true, replace: true, link: function(scope, element, attrs, ngModel) { setScopeValues(scope, attrs); var timeout, timer, helper = true, oldval = scope.val, clickStart; ngModel.$setViewValue(scope.val); scope.decrement = function() { oldval = scope.val; var value = parseFloat(parseFloat(Number(scope.val)) - parseFloat(scope.step)).toFixed(scope.decimals); if (value < scope.min) { value = parseFloat(scope.min).toFixed(scope.decimals); scope.val = value; ngModel.$setViewValue(value); return; } scope.val = value; ngModel.$setViewValue(value); }; scope.increment = function() { oldval = scope.val; var value = parseFloat(parseFloat(Number(scope.val)) + parseFloat(scope.step)).toFixed(scope.decimals); if (value > scope.max) return; scope.val = value; ngModel.$setViewValue(value); }; scope.startSpinUp = function() { scope.checkValue(); scope.increment(); clickStart = Date.now(); scope.stopSpin(); $timeout(function() { timer = $interval(function() { scope.increment(); }, scope.stepInterval); }, scope.stepIntervalDelay); }; scope.startSpinDown = function() { scope.checkValue(); scope.decrement(); clickStart = Date.now(); var timeout = $timeout(function() { timer = $interval(function() { scope.decrement(); }, scope.stepInterval); }, scope.stepIntervalDelay); }; scope.stopSpin = function() { if (Date.now() - clickStart > scope.stepIntervalDelay) { $timeout.cancel(timeout); $interval.cancel(timer); } else { $timeout(function() { $timeout.cancel(timeout); $interval.cancel(timer); }, scope.stepIntervalDelay); } }; scope.checkValue = function() { var val; if (scope.val !== '' && !scope.val.match(/^-?(?:\d+|\d*\.\d+)$/i)) { val = oldval !== '' ? parseFloat(oldval).toFixed(scope.decimals) : parseFloat(scope.min).toFixed(scope.decimals); scope.val = val; ngModel.$setViewValue(val); } }; }, template: '<div class="input-group">' + ' <span class="input-group-btn" ng-show="!verticalButtons">' + ' <button class="btn btn-default" ng-mousedown="startSpinDown()" ng-mouseup="stopSpin()"><i class="fa fa-minus"></i></button>' + ' </span>' + ' <span class="input-group-addon" ng-show="prefix" ng-bind="prefix"></span>' + ' <input type="text" ng-model="val" class="form-control" ng-blur="checkValue()">' + ' <span class="input-group-addon" ng-show="postfix" ng-bind="postfix"></span>' + ' <span class="input-group-btn" ng-show="!verticalButtons">' + ' <button class="btn btn-default" ng-mousedown="startSpinUp()" ng-mouseup="stopSpin()"><i class="fa fa-plus"></i></button>' + ' </span>' + '</div>' }; }
]);
//--- 测试代码 ---------------------------------------------------
angular.module("CodePan.Kelvin.Test.ngTouchSpin", ["jkuri.touchspin"]);
angular.module("CodePan.Kelvin.Test.ngTouchSpin").controller("ngTouchSpinCtrl", ngTouchSpinCtrl);
ngTouchSpinCtrl.$inject = ['$scope']
function ngTouchSpinCtrl($scope) { var vm = this; vm.ctrl = { val: 0 };
}
angular.bootstrap(document, ["CodePan.Kelvin.Test.ngTouchSpin"]);
Developer | Kevin |
Username | chenming142 |
Uploaded | August 28, 2022 |
Rating | 3 |
Size | 3,084 Kb |
Views | 64,768 |
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 |
A Pen by Kevin | 10,365 Kb |
NgModel validation Unit | 2,421 Kb |
Vue Transition | 4,561 Kb |
Submitability | 2,105 Kb |
JsTag | 7,050 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 |
Glowing Pulse Form | Jackrugile | 2,542 Kb |
JS Beispiel getElementsByClassName 3 | HSZG-Frontend-Kurs | 1,988 Kb |
Wikipedia Viewer | Thomasvaeth | 2,549 Kb |
Count up | Alanshortis | 2,391 Kb |
Scrolling Horizontal Isotope | Bramus | 2,017 Kb |
A Bouncy Menu Toggle | Billyysea | 4,563 Kb |
Horizontal Navigation with Floats | Gymratpacks | 5,403 Kb |
Bootstrap 4 Gridsystem Demo | Rivella50 | 1,535 Kb |
Flat UI Button | Honchoman | 2,289 Kb |
Filter inputs | Rowinf | 1,721 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!