优化 slider 的 `elem` 以支持同时渲染多个实例

pull/1216/head
贤心 2023-03-19 23:21:23 +08:00
parent 40d3c330ab
commit b8e27d6bcd
1 changed files with 19 additions and 4 deletions

View File

@ -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;