NgTouchSpin

Developer
Size
3,084 Kb
Views
64,768

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 Previews

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"]);
NgTouchSpin - Script Codes
NgTouchSpin - Script Codes
Home Page Home
Developer Kevin
Username chenming142
Uploaded August 28, 2022
Rating 3
Size 3,084 Kb
Views 64,768
Do you need developer help for NgTouchSpin?

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!

Kevin (chenming142) Script Codes
Create amazing video scripts 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!