Open modal window automatically when opening the page

1

I am trying to use the jquery .load function, replacing .click. Because the intention is for the lightbox to open while loading the page and not clicking.

JS TO OPEN THE MODAL WINDOW BY CLICKING ON A LINK

  $(document).ready(function(){
    $("a[rel=modal]").click( function(ev){
      ev.preventDefault();

      var id = $(this).attr("href");

      var alturaTela = $(document).height();
      var larguraTela = $(window).width();

      //colocando o fundo preto
      $('#mascara').css({'width':larguraTela,'height':alturaTela});
      $('#mascara').fadeIn(1000); 
      $('#mascara').fadeTo("slow",0.8);

      var left = ($(window).width() /2) - ( $(id).width() / 2 );
      var top = ($(window).height() / 3) - ( $(id).height() / 3 );

      $(id).css({'top':top,'left':left});
      $(id).show(); 
    });

    $("#mascara").load( function(){
      $(this).hide();
      $(".janelao").hide();
    });

    $('.fechar').click(function(ev){
      ev.preventDefault();
      $("#mascara").hide();
      $(".window").hide();
    });
  });

JS TO OPEN MODAL WINDOW WITH PAGE LOADING

In this part I changed the $ ("a [rel = modal]"). click for $ (window) .load and it ROUGH! But it only opens the black background and not the div #janelao

   $(document).ready(function(){
    $(window).load( function(ev){
      ev.preventDefault();

>
     $("#mascara").load( function(){
      $(this).show();
      $(".janelao").show();
    });

So my problem is to load the window div that does not load, just load the black background

    
asked by anonymous 22.08.2014 / 02:40

1 answer

2

Your problem is in the variable id

When you change from $("a[rel=modal]").click( to $(window).load( you change the value of this , so by performing var id = $(this).attr("href"); this variable gets changed value.

Change this assignment to var id = $("a[rel=modal]").attr("href"); that will work.

    
22.08.2014 / 03:39