Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Range slider
50
css
.range { position: relative; } .range input[type=range] { -webkit-appearance: none; -moz-appearance: none; appearance: none; padding: 0; width: 100%; height: 22px; cursor: pointer; display: block; } .range input[type=range]:focus { outline: none; } .range input[type=range][disabled] { opacity: .3; cursor: default; } .range .rangeslider { position: relative; height: 22px; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .range .rangeslider:before { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; content: ""; position: absolute; top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%); } .range input::-webkit-slider-runnable-track { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; margin: 11px 0; } .range input::-moz-range-track { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; margin: 11px 0; } .range input::-ms-track { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; color: transparent; padding: 11px 0; background: transparent; border-color: transparent; } .range input::-ms-fill-lower, .range input::-ms-fill-upper { box-sizing: border-box; width: 100%; height: 4px; background: #e6e6e6; border-radius: 100px; } .range input::-ms-fill-lower { background: #60cd18; } .range .rangeslider-fill-lower { background-color: #60cd18; border-radius: 100px; position: absolute; top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%); height: 4px; will-change: width; } .range input::-webkit-slider-thumb { box-sizing: border-box; box-shadow: 0px 4px 25px rgba(0, 0, 0, 0.5); border: 6px solid #fff; height: 24px; width: 24px; border-radius: 100px; background: #333940; cursor: pointer; -webkit-appearance: none; appearance: none; -webkit-transform: translateY(-50%); transform: translateY(-50%); margin-top: 2px; } .range input::-moz-range-thumb { box-sizing: border-box; box-shadow: 0px 4px 25px rgba(0, 0, 0, 0.5); border: 6px solid #fff; height: 24px; width: 24px; border-radius: 100px; background: #333940; cursor: pointer; } .range input::-ms-thumb { box-sizing: border-box; box-shadow: 0px 4px 25px rgba(0, 0, 0, 0.5); border: 6px solid #fff; height: 24px; width: 24px; border-radius: 100px; background: #333940; cursor: pointer; } .range .rangeslider-thumb { box-sizing: border-box; box-shadow: 0px 4px 25px rgba(0, 0, 0, 0.5); border: 6px solid #fff; height: 24px; width: 24px; border-radius: 100px; background: #333940; cursor: pointer; position: absolute; -ms-touch-action: pan-x; touch-action: pan-x; top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%); will-change: left; } .range .range-output { position: absolute; left: 6px; top: 6px; -webkit-transform-origin: 0 0; transform-origin: 0 0; -webkit-transition: -webkit-transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); transition: -webkit-transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), -webkit-transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .range .range-output .output { display: block; position: absolute; height: 60px; line-height: 60px; min-width: 32px; padding: 0 20px; top: -26px; -webkit-transform: translate(-50%, -100%); transform: translate(-50%, -100%); background: #383c42; color: #fff; border-radius: 100px; white-space: nowrap; font-weight: bold; font-size: 1.2em; text-align: center; } .range .range-output .output:before { content: ""; position: absolute; bottom: -8px; left: 50%; border: 10px solid #383c42; border-bottom: none; border-left-color: transparent; border-right-color: transparent; -webkit-transform: translateX(-50%); transform: translateX(-50%); } body { font-family: Helvetica Neue, Helvetica, Arial; font-weight: 300; } main { display: -webkit-box; display: -ms-flexbox; display: flex; height: 100vh; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center; color: #333; } form { max-width: 500px; min-width: 320px; } h2 { font-weight: 300; text-align: center; margin-bottom: 30px; }
JavaScript
'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var END = 'change'; var START = 'ontouchstart' in document ? 'touchstart' : 'mousedown'; var INPUT = 'input'; var MAX_ROTATION = 35; var SOFTEN_FACTOR = 3; var RangeInput = function () { function RangeInput(el) { _classCallCheck(this, RangeInput); this.el = el; this._handleEnd = this._handleEnd.bind(this); this._handleStart = this._handleStart.bind(this); this._handleInput = this._handleInput.bind(this); //Call the plugin $(this.el.querySelector('input[type=range]')).rangeslider({ polyfill: false, //Never use the native polyfill rangeClass: 'rangeslider', disabledClass: 'rangeslider-disabled', horizontalClass: 'rangeslider-horizontal', verticalClass: 'rangeslider-vertical', fillClass: 'rangeslider-fill-lower', handleClass: 'rangeslider-thumb', onInit: function onInit() { //No args are passed, so we can't change context of this var pluginInstance = this; //Move the range-output inside the handle so we can do all the stuff in css $(pluginInstance.$element).parents('.range').find('.range-output').appendTo(pluginInstance.$handle); } }); this.sliderThumbEl = el.querySelector('.rangeslider-thumb'); this.outputEl = el.querySelector('.range-output'); this.inputEl = el.querySelector('input[type=range]'); this._lastOffsetLeft = 0; this._lastTimeStamp = 0; this.el.querySelector('.rangeslider').addEventListener(START, this._handleStart); } RangeInput.prototype._handleStart = function _handleStart(e) { var _this = this; this._lastTimeStamp = new Date().getTime(); this._lastOffsetLeft = this.sliderThumbEl.offsetLeft; //Wrap in raf because offsetLeft is updated by the plugin after this fires requestAnimationFrame(function (_) { //Bind through jquery because plugin doesn't fire native event $(_this.inputEl).on(INPUT, _this._handleInput); $(_this.inputEl).on(END, _this._handleEnd); }); }; RangeInput.prototype._handleEnd = function _handleEnd(e) { var _this2 = this; //Unbind through jquery because plugin doesn't fire native event $(this.inputEl).off(INPUT, this._handleInput); $(this.inputEl).off(END, this._handleEnd); requestAnimationFrame(function (_) { return _this2.outputEl.style.transform = 'rotate(0deg)'; }); }; RangeInput.prototype._handleInput = function _handleInput(e) { var _this3 = this; var now = new Date().getTime(); var timeElapsed = now - this._lastTimeStamp || 1; var distance = this.sliderThumbEl.offsetLeft - this._lastOffsetLeft; var direction = distance < 0 ? -1 : 1; var velocity = Math.abs(distance) / timeElapsed; //pixels / millisecond var targetRotation = Math.min(Math.abs(distance * velocity) * SOFTEN_FACTOR, MAX_ROTATION); requestAnimationFrame(function (_) { return _this3.outputEl.style.transform = 'rotate(' + targetRotation * -direction + 'deg)'; }); this._lastTimeStamp = now; this._lastOffsetLeft = this.sliderThumbEl.offsetLeft; }; return RangeInput; }(); /*! rangeslider.js - v2.1.1 | (c) 2016 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */ !function (a) { "use strict"; "function" == typeof define && define.amd ? define(["jquery"], a) : "object" == (typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) ? module.exports = a(require("jquery")) : a(jQuery); }(function (a) { "use strict"; function b() { var a = document.createElement("input");return a.setAttribute("type", "range"), "text" !== a.type; }function c(a, b) { var c = Array.prototype.slice.call(arguments, 2);return setTimeout(function () { return a.apply(null, c); }, b); }function d(a, b) { return b = b || 100, function () { if (!a.debouncing) { var c = Array.prototype.slice.apply(arguments);a.lastReturnVal = a.apply(window, c), a.debouncing = !0; }return clearTimeout(a.debounceTimeout), a.debounceTimeout = setTimeout(function () { a.debouncing = !1; }, b), a.lastReturnVal; }; }function e(a) { return a && (0 === a.offsetWidth || 0 === a.offsetHeight || a.open === !1); }function f(a) { for (var b = [], c = a.parentNode; e(c);) { b.push(c), c = c.parentNode; }return b; }function g(a, b) { function c(a) { "undefined" != typeof a.open && (a.open = a.open ? !1 : !0); }var d = f(a), e = d.length, g = [], h = a[b];if (e) { for (var i = 0; e > i; i++) { g[i] = d[i].style.cssText, d[i].style.setProperty ? d[i].style.setProperty("display", "block", "important") : d[i].style.cssText += ";display: block !important", d[i].style.height = "0", d[i].style.overflow = "hidden", d[i].style.visibility = "hidden", c(d[i]); }h = a[b];for (var j = 0; e > j; j++) { d[j].style.cssText = g[j], c(d[j]); } }return h; }function h(a, b) { var c = parseFloat(a);return Number.isNaN(c) ? b : c; }function i(a) { return a.charAt(0).toUpperCase() + a.substr(1); }function j(b, e) { if (this.$window = a(window), this.$document = a(document), this.$element = a(b), this.options = a.extend({}, n, e), this.polyfill = this.options.polyfill, this.orientation = this.$element[0].getAttribute("data-orientation") || this.options.orientation, this.onInit = this.options.onInit, this.onSlide = this.options.onSlide, this.onSlideEnd = this.options.onSlideEnd, this.DIMENSION = o.orientation[this.orientation].dimension, this.DIRECTION = o.orientation[this.orientation].direction, this.DIRECTION_STYLE = o.orientation[this.orientation].directionStyle, this.COORDINATE = o.orientation[this.orientation].coordinate, this.polyfill && m) return !1;this.identifier = "js-" + k + "-" + l++, this.startEvent = this.options.startEvent.join("." + this.identifier + " ") + "." + this.identifier, this.moveEvent = this.options.moveEvent.join("." + this.identifier + " ") + "." + this.identifier, this.endEvent = this.options.endEvent.join("." + this.identifier + " ") + "." + this.identifier, this.toFixed = (this.step + "").replace(".", "").length - 1, this.$fill = a('
'), this.$handle = a('
'), this.$range = a('
').insertAfter(this.$element).prepend(this.$fill, this.$handle), this.$element.css({ position: "absolute", width: "1px", height: "1px", overflow: "hidden", opacity: "0" }), this.handleDown = a.proxy(this.handleDown, this), this.handleMove = a.proxy(this.handleMove, this), this.handleEnd = a.proxy(this.handleEnd, this), this.init();var f = this;this.$window.on("resize." + this.identifier, d(function () { c(function () { f.update(!1, !1); }, 300); }, 20)), this.$document.on(this.startEvent, "#" + this.identifier + ":not(." + this.options.disabledClass + ")", this.handleDown), this.$element.on("change." + this.identifier, function (a, b) { if (!b || b.origin !== f.identifier) { var c = a.target.value, d = f.getPositionFromValue(c);f.setPosition(d); } }); }Number.isNaN = Number.isNaN || function (a) { return "number" == typeof a && a !== a; };var k = "rangeslider", l = 0, m = b(), n = { polyfill: !0, orientation: "horizontal", rangeClass: "rangeslider", disabledClass: "rangeslider--disabled", horizontalClass: "rangeslider--horizontal", verticalClass: "rangeslider--vertical", fillClass: "rangeslider__fill", handleClass: "rangeslider__handle", startEvent: ["mousedown", "touchstart", "pointerdown"], moveEvent: ["mousemove", "touchmove", "pointermove"], endEvent: ["mouseup", "touchend", "pointerup"] }, o = { orientation: { horizontal: { dimension: "width", direction: "left", directionStyle: "left", coordinate: "x" }, vertical: { dimension: "height", direction: "top", directionStyle: "bottom", coordinate: "y" } } };return j.prototype.init = function () { this.update(!0, !1), this.onInit && "function" == typeof this.onInit && this.onInit(); }, j.prototype.update = function (a, b) { a = a || !1, a && (this.min = h(this.$element[0].getAttribute("min"), 0), this.max = h(this.$element[0].getAttribute("max"), 100), this.value = h(this.$element[0].value, Math.round(this.min + (this.max - this.min) / 2)), this.step = h(this.$element[0].getAttribute("step"), 1)), this.handleDimension = g(this.$handle[0], "offset" + i(this.DIMENSION)), this.rangeDimension = g(this.$range[0], "offset" + i(this.DIMENSION)), this.maxHandlePos = this.rangeDimension - this.handleDimension, this.grabPos = this.handleDimension / 2, this.position = this.getPositionFromValue(this.value), this.$element[0].disabled ? this.$range.addClass(this.options.disabledClass) : this.$range.removeClass(this.options.disabledClass), this.setPosition(this.position, b); }, j.prototype.handleDown = function (a) { if (this.$document.on(this.moveEvent, this.handleMove), this.$document.on(this.endEvent, this.handleEnd), !((" " + a.target.className + " ").replace(/[\n\t]/g, " ").indexOf(this.options.handleClass) > -1)) { var b = this.getRelativePosition(a), c = this.$range[0].getBoundingClientRect()[this.DIRECTION], d = this.getPositionFromNode(this.$handle[0]) - c, e = "vertical" === this.orientation ? this.maxHandlePos - (b - this.grabPos) : b - this.grabPos;this.setPosition(e), b >= d && b < d + this.handleDimension && (this.grabPos = b - d); } }, j.prototype.handleMove = function (a) { a.preventDefault();var b = this.getRelativePosition(a), c = "vertical" === this.orientation ? this.maxHandlePos - (b - this.grabPos) : b - this.grabPos;this.setPosition(c); }, j.prototype.handleEnd = function (a) { a.preventDefault(), this.$document.off(this.moveEvent, this.handleMove), this.$document.off(this.endEvent, this.handleEnd), this.$element.trigger("change", { origin: this.identifier }), this.onSlideEnd && "function" == typeof this.onSlideEnd && this.onSlideEnd(this.position, this.value); }, j.prototype.cap = function (a, b, c) { return b > a ? b : a > c ? c : a; }, j.prototype.setPosition = function (a, b) { var c, d;void 0 === b && (b = !0), c = this.getValueFromPosition(this.cap(a, 0, this.maxHandlePos)), d = this.getPositionFromValue(c), this.$fill[0].style[this.DIMENSION] = d + this.grabPos + "px", this.$handle[0].style[this.DIRECTION_STYLE] = d + "px", this.setValue(c), this.position = d, this.value = c, b && this.onSlide && "function" == typeof this.onSlide && this.onSlide(d, c); }, j.prototype.getPositionFromNode = function (a) { for (var b = 0; null !== a;) { b += a.offsetLeft, a = a.offsetParent; }return b; }, j.prototype.getRelativePosition = function (a) { var b = i(this.COORDINATE), c = this.$range[0].getBoundingClientRect()[this.DIRECTION], d = 0;return "undefined" != typeof a["page" + b] ? d = a["client" + b] : "undefined" != typeof a.originalEvent["client" + b] ? d = a.originalEvent["client" + b] : a.originalEvent.touches && a.originalEvent.touches[0] && "undefined" != typeof a.originalEvent.touches[0]["client" + b] ? d = a.originalEvent.touches[0]["client" + b] : a.currentPoint && "undefined" != typeof a.currentPoint[this.COORDINATE] && (d = a.currentPoint[this.COORDINATE]), d - c; }, j.prototype.getPositionFromValue = function (a) { var b, c;return b = (a - this.min) / (this.max - this.min), c = Number.isNaN(b) ? 0 : b * this.maxHandlePos; }, j.prototype.getValueFromPosition = function (a) { var b, c;return b = a / (this.maxHandlePos || 1), c = this.step * Math.round(b * (this.max - this.min) / this.step) + this.min, Number(c.toFixed(this.toFixed)); }, j.prototype.setValue = function (a) { (a !== this.value || "" === this.$element[0].value) && this.$element.val(a).trigger("input", { origin: this.identifier }); }, j.prototype.destroy = function () { this.$document.off("." + this.identifier), this.$window.off("." + this.identifier), this.$element.off("." + this.identifier).removeAttr("style").removeData("plugin_" + k), this.$range && this.$range.length && this.$range[0].parentNode.removeChild(this.$range[0]); }, a.fn[k] = function (b) { var c = Array.prototype.slice.call(arguments, 1);return this.each(function () { var d = a(this), e = d.data("plugin_" + k);e || d.data("plugin_" + k, e = new j(this, b)), "string" == typeof b && e[b].apply(e, c); }); }, "rangeslider.js is available in jQuery context e.g $(selector).rangeslider(options);"; }); new RangeInput(document.querySelector('.range'));
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>范围滑块-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号