How to open Pop Up automatico?

Asked

Viewed 1,628 times

1

I have the following modal code

<a href="#openModal">Clique</a>
<div id="openModal" class="modalDialog">
      <div>
        <a href="#close" title="Close" class="closeModal">
        <!-- Conteúdo do Modal -->
        <h2>Análise fiscal?</h2>
        <p>O status de "Análise Fiscal" prestado pela transportadora significa que sua encomenda foi retida pela Receita Federal para que os mesmos confiram informações constantes na nota fiscal, e verificarem se os impostos estão sendo pagos corretamente, devido às diferenças tributárias de cada estado.</p>
        <hr>
        <!-- Conteúdo do Modal -->
      </div>
    </div>
 <script type="text/javascript">
    // <![CDATA[
    document.querySelector("#go").addEventListener("submit", function(e) {
      e.preventDefault();
      window.location.replace('http://status.ondeestameupedido.com/tracking/6560/' + document.getElementById("pedido").value);


    });
    // ]]>
  </script>
<style>
  .pedido {

      margin-top: -300px;
      margin-left: 40%;
      margin-right: 40%;
      margin-bottom: 100px;

  }

  .teste {

  padding-top: 100px;

  }
.modalDialog {
  position: fixed;
  font-family: Arial, Helvetica, sans-serif;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0,0,0,0.8);
  z-index: 99999;
  opacity:0;
  -webkit-transition: opacity 400ms ease-in;
  -moz-transition: opacity 400ms ease-in;
  transition: opacity 400ms ease-in;
  pointer-events: none;
}
.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;
}
.closeModal {
  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;
}
.closeModal:after {
  content: "\d7";
}
.closeModal:hover { 
  background: #f00; 
}

</style>

When I click on the word "Click" it opens. As I should do for it to open automatically when opening the page without needing to click something?

1 answer

2


You can just reverse the logic. Let it start with opacity:1, and when you click the button X to close you use the :target to place opacity:0

.pedido {
    margin-top: -300px;
    margin-left: 40%;
    margin-right: 40%;
    margin-bottom: 100px;
}

.teste {
    padding-top: 100px;
}

.modalDialog {
    position: fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 99999;
    opacity:1;
    -webkit-transition: opacity 400ms ease-in;
    -moz-transition: opacity 400ms ease-in;
    transition: opacity 400ms ease-in;
    /* pointer-events: none; */
}

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

.modalDialog>div {
    width: 400px;
    position: relative;
    margin: 10% auto;
    padding: 5px 20px 13px 20px;
    border-radius: 10px;
    background: #fff;
}

.closeModal {
    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;
}

.closeModal:after {
    content: "\d7";
}

.closeModal:hover {
    background: #f00;
}
<div id="openModal" class="modalDialog">
    <div>
        <a href="#openModal" title="Close" class="closeModal"></a>
            <!-- Conteúdo do Modal -->
            <h2>Análise fiscal?</h2>
            <p>O status de "Análise Fiscal" prestado pela transportadora significa que sua encomenda foi retida
                pela Receita Federal para que os mesmos confiram informações constantes na nota fiscal, e
                verificarem se os impostos estão sendo pagos corretamente, devido às diferenças tributárias de cada
                estado.</p>
            <hr>
            <!-- Conteúdo do Modal -->
    </div>
</div>

  • It worked, but when I close I can’t click anywhere on the page. Would you know what might be causing this? I use the platform Gento, I am putting as static block and choosing the page to be shown with widget.

  • 1

    @JVEUZEBIO I imagined this could happen!! , it happens because in this code you are not "removing" the popup from the screen, you are just taking the opacity,. It becomes transparent, but it’s actually still there on top of everything :/.. This popup model is kind of tricky to use anyway. I’ll think of something to help you with that option, or else you’ll have to use another model... give me a few minutes

  • Ah understood, if you have any idea of another model would help me a lot

  • @JVEUZEBIO guy will not look so cute with this transition effect, but if you change where is opacity:0, by display:None, and where is opacity:1 by display:block, you get what you want. using the display:None vc will remove the element from the screen, and can click on whatever is on the screen, only it will disappear at once, and not with this transition....

  • 1

    Oh cool, yes got more direct. But solved my problem, thank you!

  • Know some way to hide #openModal from url?]

  • @JVEUZEBIO can only clean using JS or jQuery, and I don’t know anything about JS. The problem is that this popup template uses :target to set the CSS in the popup, so that’s why it "dirty" the url. I think I’ve seen something here on the website about this, you’re gonna have to research it...

  • Ah right, I’ll do a search thank you

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.