开发环境
Drawer 在 弹出层 UI 上带来不一样的体验.

显示代码

								
							
抽屉

显示代码

								layui.use(['drawer'], function() {
									var drawer = layui.drawer;
								
								    drawer.open({
								        direction: "right",
								        dom: ".layer-top",
								        distance: "30%"
								    });
								})
							
进阶

显示代码

								var dom;
								
								$(".drawer-close-mask").click(function() {
								    dom = drawer.open({
								        direction: "right",
								        dom: ".layer-close-mask",
								        distance: "30%",
								        maskClose: false
								    });
								})
								
								$("#btnClose").click(function() {
								    dom.close();
								})
								
							
扩展

显示代码

								layui.use(['drawer'], function() {
									var drawer = layui.drawer;
								
								    $(".drawer-auto-close").click(function() {
								        dom = drawer.open({
								            direction: "right",
								            dom: ".layer-auto-close",
								            distance: "30%",
								            maskClose: false,
								            time: 1000
								        });
								    })
								})
							
扩展

显示代码

								layui.use(['drawer'], function() {
									var drawer = layui.drawer;
								
								    $(".drawer-auto-close").click(function() {
								        dom = drawer.open({
								            direction: "right",
								            dom: ".layer-auto-close",
								            distance: "30%",
								            success:function(){
								                layer.msg("触发回调函数"); 
								            }
								        });
								    })
								})
							
扩展

显示代码

									layui.use(['drawer'], function() {
									  var drawer = layui.drawer;
									    $("#targetDemo").click(function () {
									      drawer.open({
									      // 指定挂载节点
									      target: "#targetEl"
									      direction: "right",
									      dom: ".layer-right",
									      distance: "50%",
									      });
									})
							
基于 layer 的抽屉扩展

兼容原版 drawer 所有参数,要使用 layer 扩展,设置 legacy 选项为 false 即可

指定容器内打开,需使用 layer 捕获层模式,并设置目标容器 style="overflow: hidden; position: relative;"

显示代码

											$("#layerDrawerLeft").click(function(){
											  drawer.open({
											    legacy: false,
											    offset: 'l',
											    area: "30%",
											    content: "left内容",
											  })
											})
											$("#layerDrawerRight").click(function () {
											  drawer.open({
											    legacy: false,
											    offset: 'r',
											    area: "30%",
											    content: "right内容",
											  })
											})
											$("#layerDrawerTop").click(function () {
											  drawer.open({
											    legacy: false,
										      offset: "t",
											    content: "top内容",
											  })
											})
											$("#layerDrawerBottom").click(function () {
											  drawer.open({
											    legacy: false,
											    offset: "b",
											    content: "bottom内容",
											  })
											})
											
											$("#layerDrawer").click(function () {
											  var index = drawer.open({
											    legacy: false,
											    title: ['标题', 'font-size:16px;color:#2d8cf0'],
											    maxmin: true,
											    offset: "r",
											    area: "30%",
											    content: "抽屉内容",
											    btn:"关闭",
											    yes:function(index,layero){
											      drawer.close(index);
											      console.log(index,layero);
											    },
											    btnAlign: "l",
											    closeBtn: 1,
											  })
											})

											$("#layerDrawerParent").click(function () {
											    
											  var index = parent.layui.drawer.open({
												    legacy: false,
												    title: ['标题', 'font-size:16px;color:#2d8cf0'],
												    maxmin: true,
												    offset: "r",
												    area: "30%",
												    content: "抽屉内容",
												    btn:"关闭",
												    yes:function(index,layero){
												      drawer.close(index);
												      console.log(index,layero);
												    },
												    btnAlign: "l",
												    closeBtn: 1,
												})
											})

											$("#layertargetDemo").click(function () {
											    drawer.open({
											    legacy: false,
											    target: "#layertargetEl",
											    direction: "right",
											    dom: ".layer-right",
											    distance: "50%",
											    });
											})