解决layer弹窗不刷新状态下第一次不居中,再次点击就居中了

网上收集的有三种方法(不过自己不怎么适用):

方法一。把弹窗事件写在layer.ready里面

             layer.ready(function() {
                        var index = layer.load(2);
                        layer.open({
                            type: 1,
                            title: false,
                            closeBtn: 0,
                            shadeClose: true,
                            area: ['200px', 'auto'],
                            content: '<img class="closeCode" src="' + dataimg + '" width="100%" />',
                        });
                        layer.close(index);
                    });

 

方法二。在成功以后修改样式

              layer.open({
                            type: 1,
                            title: false,
                            closeBtn: 0,
                            shadeClose: true,
                            area: ['200px', 'auto'],
                            content: '<img class="closeCode" src="' + dataimg + '" width="100%" />',
                            success:function(layero,index){
                                layer.style(index, {
                                   top: '50%',
                                   transform:'translateY(-50%)'
                                });
                            }
                        });

方法三。写个固定的宽高

           layer.open({
                            type: 1,
                            title: false,
                            closeBtn: 0,
                            shadeClose: true,
                            area: ['200px', '200px'],
                            content: '<img class="closeCode" src="' + dataimg + '" width="100%" />',
                        });
我的是监听表格事件的弹窗:

  

  第一个方法试过无效。

  第二种方法第一次点击的时候正常,但第二次点击就变了。

    对此稍微改了一点,添加一个按钮使第一次点击时渲染样式,第二点击无法渲染

      

      注意:var flag = true时放在    //监听行工具事件  外面

        

  第三种不适用。

posted @ 2020-03-04 14:32  星空下的boys  阅读(833)  评论(0编辑  收藏  举报