0

我有一个 jquery 弹出插件,当我提交表单时它会自动关闭。但我需要为弹出窗口设置时间限制。

HTML:

  <div class='popbox'>
<a class='open' href='#'>
  <img src='plus.png' style='width:14px;position:relative;'> Click Here!
</a>

<div class='collapse'>
  <div class='box'>
    <div class='arrow'></div>
    <div class='arrow-border'></div>

    <form action="" method="post" id="subForm">
      <div class="input">
        <input type="text" name="cm-name" id="name" placeholder="Name" />
      </div>
      <div class="input">
        <input type="text" name="cm-nklki-nklki" id="nklki-nklki" placeholder="Email" />
      </div>
      <div class="input">
        <textarea name="cm-f-tlhll" id="Message" placeholder="Comments"></textarea>
      </div>
      <input type="submit" value="Get In Touch" /> <a href="#" class="close">Cancel</a>
      <input type="button" name="closebutton" id="closebutton" value="closebutton" >
    </form>

  </div>
</div>

查询:

 (function () {
   $.fn.popbox = function (options) {
     var settings = $.extend({
       selector: this.selector,
       open: '.open',
       box: '.box',
       arrow: '.arrow',
       arrow_border: '.arrow-border',
       close: '.close'
     }, options);
     var methods = {
       open: function (event) {
         event.preventDefault();
         var pop = $(this);
         var box = $(this).parent().find(settings['box']);
         if (box.css('display') == 'block') {
           methods.delay(1500).close();
         } else {
           box.css({
             'display': 'block',
             'top': 10,
             'left': ((pop.parent().width() / 2) - box.width() / 2)
           });
         }
       },
       close: function () {
         $(settings['box']).fadeOut("fast");
       }
     };
     $(document).bind('keyup', function (event) {
       if (event.keyCode == 27) {
         methods.delay(1500).close();
       }
     });
     return this.each(function () {
       //$(this).css({'width': $(settings['box']).width()}); // Width needs to be set otherwise popbox will not move when window resized.
       $(settings['open'], this).bind('click', methods.open);
       $(settings['open'], this).parent().find(settings['close']).bind('click', function (event) {
         event.preventDefault();
         methods.close();
       });
     });
   }
 }).call(this);
4

2 回答 2

0

将 增加到delay(1500)更高的值。1500 以毫秒为单位,这意味着您当前的弹出窗口将在 1.5 秒内关闭。

于 2013-02-12T05:37:07.697 回答
0
close: function () {
    window.setTimeout(function() {
        $(settings['box']).fadeOut("fast");
    }, 1000); // 1 second
}
于 2013-02-12T05:37:11.677 回答