From b8e27d6bcd062c867b11a7f70b2196856e4a9244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sun, 19 Mar 2023 23:21:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20slider=20=E7=9A=84=20`elem?= =?UTF-8?q?`=20=E4=BB=A5=E6=94=AF=E6=8C=81=E5=90=8C=E6=97=B6=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=A4=9A=E4=B8=AA=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/slider.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/modules/slider.js b/src/modules/slider.js index 3dbaf586..a3f6bb20 100644 --- a/src/modules/slider.js +++ b/src/modules/slider.js @@ -2,10 +2,11 @@ * slider 滑块组件 */ -layui.define('jquery', function(exports){ +layui.define(['jquery', 'lay'], function(exports){ 'use strict'; - var $ = layui.$ + var $ = layui.$; + var lay = layui.lay; // 外部接口 var slider = { @@ -80,8 +81,22 @@ layui.define('jquery', function(exports){ //滑块渲染 Class.prototype.render = function(){ - var that = this - ,options = that.config; + var that = this; + var options = that.config; + + // 若 elem 非唯一,则拆分为多个实例 + var elem = $(options.elem); + if(elem.length > 1){ + layui.each(elem, function(){ + slider.render($.extend({}, options, { + elem: this + })); + }); + return that; + } + + // 合并 lay-options 属性上的配置信息 + $.extend(options, lay.options(elem[0])); //间隔值不能小于 1 if(options.step < 1) options.step = 1;