在文档准备好时触发弹出式窗口或div id [英] trigger popup or div id on document ready

查看:108
本文介绍了在文档准备好时触发弹出式窗口或div id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助以在网页加载时触发弹出式窗口。

I need help to trigger popup on page load.

目前,当我点击hello链接时,弹出窗口将打开。

Currently the popup will open when i click "hello" link.

预期结果:

弹出式窗口应在不点击文档就绪

Popup should open without clicking the hyperlink or popup on document ready

HTML

<a class="button2" href="#popup1">hello</a>

<div id="popup1" class="overlay">
<div class="popup">
    <div class="contentSpec">
        <h2>Would you like to visit</h2>
        <h1>someURL</h1>
    </div>
    <a class="close" href="#"></a>
    <div class="content">

        <div class="box">
        <a class="button" href="#popup1">YES</a>
        <a class="button1" href="#popup1">NO</a>
        </div>
    </div>
</div>
</div>

CSS

body {
  font-family: Arial, sans-serif;
  background-size: cover;
}


.box {
  margin: 6% auto 3% auto;
  padding: 35px;
  background-clip: padding-box;
  text-align: center;
}

.button, .button1 {
    padding: 1.5% 4% 1.5% 4%;
    margin: 2%!important;
    text-decoration:none;
    -webkit-box-sizing: content-box;
    -moz-box-sizing: content-box;
    box-sizing: content-box;
    cursor: pointer;
    margin: 0 auto; 
    -webkit-border-radius: 40px;
    border-radius: 40px;
    font: normal 1em;
    text-align: center;
    -o-text-overflow: clip;
    text-overflow: clip;
    letter-spacing: 1px;
    background: rgba(0,0,0,0);
    -webkit-transition: background-color 0.3s cubic-bezier(0, 0, 0, 0), color 0.3s cubic-bezier(0, 0, 0, 0), width 0.3s cubic-bezier(0, 0, 0, 0), border-width 0.3s cubic-bezier(0, 0, 0, 0), border-color 0.3s cubic-bezier(0, 0, 0, 0);
    -moz-transition: background-color 0.3s cubic-bezier(0, 0, 0, 0), color 0.3s cubic-bezier(0, 0, 0, 0), width 0.3s cubic-bezier(0, 0, 0, 0), border-width 0.3s cubic-bezier(0, 0, 0, 0), border-color 0.3s cubic-bezier(0, 0, 0, 0);
    -o-transition: background-color 0.3s cubic-bezier(0, 0, 0, 0), color 0.3s cubic-bezier(0, 0, 0, 0), width 0.3s cubic-bezier(0, 0, 0, 0), border-width 0.3s cubic-bezier(0, 0, 0, 0), border-color 0.3s cubic-bezier(0, 0, 0, 0);
    transition: background-color 0.3s cubic-bezier(0, 0, 0, 0), color 0.3s cubic-bezier(0, 0, 0, 0), width 0.3s cubic-bezier(0, 0, 0, 0), border-width 0.3s cubic-bezier(0, 0, 0, 0), border-color 0.3s cubic-bezier(0, 0, 0, 0);
}
.button{
    border: 2px solid rgb(30,205,151);
    color: rgb(30, 205, 151);
}
.button1{
    border: 2px solid orange;
    color: orange;
}
.button:hover {
    background: rgb(30,205,151);
    color:#fff;
}
.button1:hover {
    background: orange;
    color:#fff;
}

.overlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  transition: opacity 500ms;
  visibility: hidden;
  opacity: 0;
}
.overlay:target {
  visibility: visible;
  opacity: 1;
}

.popup {
  margin: 70px auto;
  padding: 5% 2%;
  background: #fff;
  border-radius: 40px;
  border:10px solid #ccc;
  width: 50%;
  border:3px solid rgba(55, 174, 204, 0.9);
  position: relative;
  transition: all 5s ease-in-out;
}

.popup h2 {
  margin-top: 0;
  color: #666;
  font-size: 40px;
  text-align:center;
  font-family: Tahoma, Arial, sans-serif;
  padding-bottom:10px;
  margin:0;
}
.popup h1 {
  margin-top: 0;
  color: #333;
  font-size:40px;
  text-align:center;
  font-family: Tahoma, Arial, sans-serif;
}
.popup .close {
  position: absolute;
  top: 0px;
  right: 2%;
  transition: all 200ms;
  font-size: 80px;
  font-weight: bold;
  text-decoration: none;
  border-radius:50px;
  color: #333;
}
.popup .close:before {
  content: "×";
}
.popup .close:hover {
  color: orange;
}
.popup .content {
  max-height: 30%;
  text-align:center;
  overflow: auto;
}

.product{
color:#777;
}
.contentSpec{
margin:0 auto;
text-align:center;
}

JS

$(document).ready(function() {
    $(".button2").trigger('click');
});

FIDDLE

任何帮助,请提前感谢。

Any help is appreciated, thanks in advance.

推荐答案

我相信这是您要找的?

$(document).ready(function() {
    window.location.hash = "#popup1";
});

这是更新的小提琴

这篇关于在文档准备好时触发弹出式窗口或div id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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