打开弹出窗口时禁用后台所有内容 [英] Disable everything in background while a popup is open

查看:64
本文介绍了打开弹出窗口时禁用后台所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过单击一个按钮(#but1)打开一个弹出窗口,并通过应用以下jquery使用按钮(#but2)将其关闭-

I open a pop-up by clicking on a button(#but1) and close it using button(#but2) by applying following jquery-

$(document).ready(function(){
    $("#but1").click(function(){
            $("#popdiv").fadeTo(200,1);           
        });
    $("#but2").click(function(){
            $("#popdiv").fadeOut(200);              
        });
});

弹出窗口的CSS是-

#popdiv
{
    height:300px;
    width:420px;
    background-color:#97ceaa;
    position:fixed;
    top:200px;
    left:250px;
    display:none;
}

我想在弹出窗口出现后禁用背景.弹出窗口出现后,应禁用鼠标悬停效果,并且我不应该在背景上单击任何东西.我怎样才能做到这一点?是否可以仅使用CSS来做到这一点?

I want to disable the background after my pop-up appears. After my pop-up appears the mouse-hover effects should be disabled, and I should not be able to click anything at the back-ground. How can I achieve this? Is it possible to do this using only CSS?

推荐答案

只需将其放在另一个填充页面(并显示该页面)的容器中:

Just put it inside another container that fills the page (and show that):

$(function() {
  $("#but1").click(function() {
    $(".fullscreen-container").fadeTo(200, 1);
  });
  $("#but2").click(function() {
    $(".fullscreen-container").fadeOut(200);
  });
});

.fullscreen-container {
  display: none;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(90, 90, 90, 0.5);
  z-index: 9999;
}

#popdiv {
  height: 300px;
  width: 420px;
  background-color: #97ceaa;
  position: fixed;
  top: 50px;
  left: 50px;
}

body {
  padding-top: 65px;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="but1">Open dialog</button>
<div class="fullscreen-container">
  <div id="popdiv">
    <h1>
      Dialog content!
    </h1>
    <button id="but2">Close dialog</button>
  </div>
</div>

这篇关于打开弹出窗口时禁用后台所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆