Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何仅显示模态图像并隐藏主设计_Javascript_Html_Css - Fatal编程技术网

Javascript 如何仅显示模态图像并隐藏主设计

Javascript 如何仅显示模态图像并隐藏主设计,javascript,html,css,Javascript,Html,Css,下面是我的模式弹出窗口的样式和脚本。所有页面都使用相同的样式和脚本,但在一个特定页面中,它以这种方式显示图像,并且仅显示弹出窗口图像。单击图像时,我需要隐藏div包装。我如何才能做到这一点 <!-- The Modal --> <div id="myModal" class="modal" style="z-index:1001"> <span class="close">×</span> <%-- <img class="mo

下面是我的模式弹出窗口的样式和脚本。所有页面都使用相同的样式和脚本,但在一个特定页面中,它以这种方式显示图像,并且仅显示弹出窗口图像。单击图像时,我需要隐藏div包装。我如何才能做到这一点

 <!-- The Modal -->
<div id="myModal" class="modal" style="z-index:1001">
  <span class="close">×</span>
 <%-- <img class="modal-content" id="img01" src="images/MeetingQA.PNG">--%>
    <img class="modal-content" id="img02" src="images/Meeting1.PNG" />
    <script>
        // Get the modal
        var modal = document.getElementById('myModal');

        // Get the image and insert it inside the modal - use its "alt" text as a caption
        var img = document.getElementById('myImg');
        //var modalImg = document.getElementById("img01");
        var modalImg1 = document.getElementById("img02");
        var captionText = document.getElementById("caption");
        img.onclick = function () {
            modal.style.display = "block";
            $(".box").hide();
            $(".categories").hide();
            $(".content").hide();
            //modalImg.src = "HelpDocs/MeetingQA.PNG";
            modalImg1.src = "HelpDocs/AR/Reports/Collection%20Completed%20Work/Collectioncompleted_Agent.PNG";
        }
        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];

        // When the user clicks on <span> (x), close the modal
        span.onclick = function () {
            modal.style.display = "none";
        }
    </script>

  <style>
#myImg {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
}

/* Caption of Modal Image */
#caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}


/* Add Animation */
.modal-content, #caption {    
      -webkit-animation-name: zoom;
    -webkit-animation-duration: 0.6s;
    animation-name: zoom;
    animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
    from {-webkit-transform:scale(0)} 
    to {-webkit-transform:scale(1)}
}

@keyframes zoom {
    from {transform:scale(0)} 
    to {transform:scale(1)}
}

/* The Close Button */
.close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
}

.close:hover,
.close:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
    .modal-content {
        width: 100%;
    }
}
</style> 

×
//获取模态
var modal=document.getElementById('myModal');
//获取图像并将其插入模式-使用其“alt”文本作为标题
var img=document.getElementById('myImg');
//var modalImg=document.getElementById(“img01”);
var modalImg1=document.getElementById(“img02”);
var captionText=document.getElementById(“caption”);
img.onclick=函数(){
modal.style.display=“块”;
$(“.box”).hide();
$(“.categories”).hide();
$(“.content”).hide();
//modalImg.src=“HelpDocs/MeetingQA.PNG”;
modalImg1.src=“HelpDocs/AR/Reports/Collection%20Completed%20Work/Collectioncompleted\u Agent.PNG”;
}
//获取关闭模态的元素
var span=document.getElementsByClassName(“关闭”)[0];
//当用户单击(x)时,关闭模式对话框
span.onclick=函数(){
modal.style.display=“无”;
}
#myImg{
边界半径:5px;
光标:指针;
过渡:0.3s;
}
#myImg:hover{opacity:0.7;}
/*模态(背景)*/
.莫代尔{
显示:无;/*默认情况下隐藏*/
位置:固定;/*保持原位*/
z指数:1;/*位于顶部*/
填充顶部:100px;/*框的位置*/
左:0;
排名:0;
宽度:100%;/*全宽*/
高度:100%;/*全高*/
溢出:自动;/*根据需要启用滚动*/
背景色:rgb(0,0,0);/*回退色*/
背景色:rgba(0,0,0,0.9);/*黑色w/不透明度*/
}
/*模态内容(图像)*/
.模态内容{
保证金:自动;
显示:块;
宽度:80%;
最大宽度:700px;
}
/*模态图像字幕*/
#标题{
保证金:自动;
显示:块;
宽度:80%;
最大宽度:700px;
文本对齐:居中;
颜色:#ccc;
填充:10px0;
高度:150像素;
}
/*添加动画*/
.模式内容#标题{
-webkit动画名称:缩放;
-webkit动画持续时间:0.6s;
动画名称:缩放;
动画持续时间:0.6s;
}
@-webkit关键帧缩放{
来自{-webkit变换:缩放(0)}
到{-webkit转换:缩放(1)}
}
@关键帧缩放{
来自{transform:scale(0)}
到{变换:比例(1)}
}
/*关闭按钮*/
.结束{
位置:绝对位置;
顶部:15px;
右:35px;
颜色:#f1f1;
字体大小:40px;
字体大小:粗体;
过渡:0.3s;
}
.关闭:悬停,
.结束:聚焦{
颜色:#bbb;
文字装饰:无;
光标:指针;
}
/*较小屏幕上的100%图像宽度*/
@仅介质屏幕和(最大宽度:700px){
.模态内容{
宽度:100%;
}
}

当我尝试运行代码段时,我得到了这样的结果:{“message”:“uncaughttypeerror:无法将属性'onclick'设置为null”,“filename”:“lineno”:111,“colno”:25}尝试使用其他联机编辑器,以便更容易解决问题我想您需要类似的内容您尝试了链接吗?