带有HTML5和css3的模态窗口

时间:2017-11-22 05:56:03

标签: javascript jquery css html5 css3

你好我正在使用这个带有html5和css3

的模态Windows的弹出窗口

Htlml:

<a href="#openModal">Open Modal</a>
<div id="openModal" class="modalDialog">
    <div>
        <a href="#close" title="Close" class="close">X</a>
        <h2>Modal Box</h2>
        <p>This is a sample modal box that can be created using the powers of CSS3.</p>
        <p>You could do a lot of things here like have a pop-up ad that shows when your website loads, or create a login/register form for users.</p>
    </div>
</div>

的CSS:

.modalDialog:target {
    opacity: 1;
    pointer-events: auto;
}

.modalDialog > div {
    width: 400px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    border-radius: 10px;
    background: #fff;
    background: -moz-linear-gradient(#fff, #999);
    background: -webkit-linear-gradient(#fff, #999);
    background: -o-linear-gradient(#fff, #999);
}

.close {
    background: #606061;
    color: #FFFFFF;
    line-height: 25px;
    position: absolute;
    right: -12px;
    text-align: center;
    top: -10px;
    width: 24px;
    text-decoration: none;
    font-weight: bold;
    -webkit-border-radius: 12px;
    -moz-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 1px 1px 3px #000;
    -webkit-box-shadow: 1px 1px 3px #000;
    box-shadow: 1px 1px 3px #000;
}

.modalDialog > div {
    width: 400px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    border-radius: 10px;
    background: #fff;
    background: -moz-linear-gradient(#fff, #999);
    background: -webkit-linear-gradient(#fff, #999);
    background: -o-linear-gradient(#fff, #999);
}

.close {
    background: #606061;
    color: #FFFFFF;
    line-height: 25px;
    position: absolute;
    right: -12px;
    text-align: center;
    top: -10px;
    width: 24px;
    text-decoration: none;
    font-weight: bold;
    -webkit-border-radius: 12px;
    -moz-border-radius: 12px;
    border-radius: 12px;
    -moz-box-shadow: 1px 1px 3px #000;
    -webkit-box-shadow: 1px 1px 3px #000;
    box-shadow: 1px 1px 3px #000;
}

.close:hover {
    background: #00d9ff;
} 

问题是:
当视频在窗口内播放并关闭时,视频不会停止,我仍然可以在后台听到声音。有没有办法强制重置或停止视频?

1 个答案:

答案 0 :(得分:0)

通过jQuery函数试试这个。检查fidde link

JS:

$(document).ready(function () {
    $("#vid")[0].pause();
};

function hidevideo() {
    document.getElementById("openModal").style.display = "none";
    $("#vid")[0].pause();
};

function openvideo() {
    document.getElementById("openModal").style.display = "block";
    setTimeout(function () {
        $("#vid")[0].play();
    }, 200);
    $("#vid")[0].play();
};

HTML:

<a onclick="openvideo();">Open Modal</a>
<div id="openModal" class="modalDialog">
  <div>
    <a href="javascript;" title="Close" class="close" onclick="hidevideo()">X</a>
    <h2>Modal Box</h2>
    <video autoplay="autoplay" id="vid" preload="none" controls>
      <source src="video/video.mp4" type="video/mp4">
    </video>
  </div>
</div>