layer弹窗弹出位置不在浏览器窗口居中的问题的解决方法

问题描述:

layer弹窗的弹出位置不在浏览器视口居中,而是根据页面内容居中了,导致页面内容很长时,看不到弹窗,滚动滚动条才能看到,通常情况下,这并不满足需求。

解决方法:

使用parent.layer来调用弹窗,这样,弹窗的位置就会相对于上一级的window定位,而不是当前所在的window了
注意:通过parent.layer调用时,父级页面也要引用layer.js
解决方法改进:有的时候,弹窗的内嵌层数比较多,那么就需要parent.parent.layer了,所以,直接使用top.layer更加方便

<script src="layer-v3.1.1/layer/layer.js"></script>
<script>
    $(document).ready(function() {
        $('.cancel-btn').click(function() {
            parent.layer.open({
              type: 2,
              content: 'http://sentsin.com', 
            });
        });
    });
</script>


参考原文:https://blog.csdn.net/qq_38706757/article/details/80855608

猜你喜欢

转载自www.cnblogs.com/chaoyueqi/p/10106947.html
今日推荐