【问题标题】:Modal with embedded pdf带有嵌入式 pdf 的模态
【发布时间】:2016-11-23 19:08:54
【问题描述】:

我正在尝试在我正在制作的具有嵌入式 PDF 的网站上放置一个模式。

pdf 显示得非常小。我不是从头开始编写这段代码的。我在另一个网站上找到了它。有人可以帮忙吗?

我正在使用 Zurb Foundation 框架,仅供参考。

https://jsfiddle.net/8ryeqfbc/

HTML----

<section class="modal">
            <div class="wrap row small-up-1 medium-up-1">
                <div class="special column"><h3>Modal</h3>
                    <!-- Trigger/Open The Modal -->
                        <button id="myBtn">View Full Menu</button>

                        <!-- The Modal -->
                        <div id="myModal" class="modal">

                        <!-- Modal content -->
                        <div class="modal-content">
                            <span class="close">x</span>
                            <iframe src="pdf.pdf"></iframe>
                        </div>
                    </div>
                </div>             
            </div>
    </section>

Javascript ---

<script>
// Get the modal
var modal = document.getElementById('myModal');

// Get the button that opens the modal
var btn = document.getElementById("myBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on the button, open the modal 
btn.onclick = function() {
    modal.style.display = "block";
}

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

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
</script>

CSS-----

* 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: 500px; /* Full width */
    height: 500px; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    position: relative;
    background-color: #fefefe;
    margin: auto;
    padding: 0;
    border: 1px solid #888;
    width: 95%;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s
}

/* Add Animation */
@-webkit-keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
}

@keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
}

/* The Close Button */
.close {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

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

.modal-header {
    padding: 2px 16px;
    background-color: #5cb85c;
    color: white;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
    padding: 2px 16px;
    background-color: #5cb85c;
    color: white;
}

【问题讨论】:

    标签: javascript html css iframe simplemodal


    【解决方案1】:

    设置iframe 的样式以使其填充模态框。

    .modal-content iframe {
      height: 100%;
      width: 100%;
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-25
      • 1970-01-01
      • 2014-12-19
      • 2015-12-23
      • 1970-01-01
      • 2012-09-20
      • 2012-12-06
      • 2017-08-13
      • 1970-01-01
      相关资源
      最近更新 更多