【问题标题】:Blur content on modal show event模态显示事件上的模糊内容
【发布时间】:2019-06-21 13:09:14
【问题描述】:

我正在尝试更改我所有网站内容所在的类(包装器),基本上当用户单击模式打开时,我将样式添加到类“包装器”,我' m 使用.modal-backgrop.in CSS 再添加一个 CSS,即模糊,但不起作用。

这里是风格:

.modal-backdrop.in+#wrapper {
    -webkit-filter: blur(10px);
    -moz-filter: blur(10px);
    -o-filter: blur(10px);
    -ms-filter: blur(10px);
    filter: blur(10px);
}

【问题讨论】:

  • 请通过创建 sn-p 或 fiddle 发布完整的相关代码
  • 你想设计什么风格?包装器还是模态背景?与此对应的 HTML 是什么?
  • 您的包装元素不是一个类,它被选为一个 id(“#name”表示“id=name 的 html 元素”)。您的意思是“.wrapper”吗?
  • @epascarello 我试图在模式背景被触发时设置包装器的样式

标签: javascript html css twitter-bootstrap-3 bootstrap-modal


【解决方案1】:

如果我理解正确,您正试图使模态背后的内容变得模糊。要获得这种效果,您可以尝试以下方法之一:

使用backdrop-filter

这个还是experimental CSS property;然而,它非常简单,因为它将过滤器应用于半透明元素后面的内容。这种方法的实现是:

.modal-backdrop.in + #wrapper {
    backdrop-filter: blur(10px);  
    -webkit-backdrop-filter: blur(10px);
}

请注意,由于它仍处于试验阶段,因此不应在生产中使用。

页面本身的样式

使用 JavaScript,您可以向 #wrapper 元素添加一个类,例如 .modal-open,然后适当地设置它的样式,或多或少像这样(如果过滤器在包装器内,请记住从模式中删除过滤器) :

JS

const wrapper = document.getElementById('wrapper');

function openModal () {
    // ...
    wrapper.classList.add('modal-open');
}

function closeModal () {
    // ...
    wrapper.classList.remove('modal-open');
}

CSS

#wrapper.modal-open {
    filter: blur(10px);
}

#modal {
    filter: none;
}

【讨论】:

    猜你喜欢
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    相关资源
    最近更新 更多