簡體   English   中英

jQuery彈出框的關閉按鈕

[英]close button for jquery popup box

我正在使用此代碼作為彈出框,並且效果很好

   $(document).ready(function() {

  // Here we will write a function when link click under class popup                   
   $('a.popup').click(function() {


 // Here we will describe a variable popupid which gets the
  // rel attribute from the clicked link                            
   var popupid = $(this).attr('rel');


// Now we need to popup the marked which belongs to the rel attribute
 // Suppose the rel attribute of click link is popuprel then here in below code
  // #popuprel will fadein
$('#' + popupid).fadeIn();


  // append div with id fade into the bottom of body tag
 // and we allready styled it in our step 2 : CSS
   $('body').append('<div id="fade"></div>');
   $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();


    // Now here we need to have our popup box in center of 
   // webpage when its fadein. so we add 10px to height and width 
     var popuptopmargin = ($('#' + popupid).height() + 10) / 2;
    var popupleftmargin = ($('#' + popupid).width() + 10) / 2;


   // Then using .css function style our popup box for center allignment
     $('#' + popupid).css({
  'margin-top' : -popuptopmargin,
    'margin-left' : -popupleftmargin
     });
    });


     // Now define one more function which is used to fadeout the 
     // fade layer and popup window as soon as we click on fade layer
      $('#fade').click(function() {


     // Add markup ids of all custom popup box here                           
        $('#fade , #popuprel , #popuprel2 , #popuprel3').fadeOut()
     return false;
     });
      });

這是我的HTML代碼:

<div class="popupbox" id="popuprel">
     <div id="intabdiv">
          <h2>Content Demo 1</h2>
               <p>Check out WebDesignersDesk for more tutorials</p> 

      </div>
  </div>
<div id="fade"></div>

但是我的彈出框僅在單擊外部彈出框時關閉,但我想在框內添加一個關閉按鈕,然后單擊以關閉框。 怎么辦?

嘗試這個..

HTML:

<div class="popupbox" id="popuprel">
     <div id="intabdiv">
          <h2>Content Demo 1</h2>
               <p>Check out WebDesignersDesk for more tutorials</p> 

      </div>
      <div class="closepopup">Close</div>
</div>
<div id="fade" class="fade"></div>

Javascript:

$('.closepopup').on('click', function(e) {
    $('.popupbox').fadeOut();
    $('.fade').fadeOut();
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM