$(document).ready()在Jquery插件方法中?

时间:2012-03-27 14:19:01

标签: javascript jquery jquery-plugins document-ready

我试图从jquery lighbox插件中修改一下'resize'方法,具体取决于div#id是否存在。

我这样撒谎:

 resize: function(x, y) {
        if (this.visible) {
          var size   = { x: $(window).width(),      y: $(window).height() };
          var scroll = { x: $(window).scrollLeft(), y: $(window).scrollTop() };
          var left   = (scroll.x + (size.x - (x + 14)) / 2);
          var top    = (scroll.y + (size.y - (y + 14)) / 2);
          console.log(size);
          if ($.browser.msie || ($.browser.mozilla && (parseFloat($.browser.version) < 1.9))) {
            y += 4;
          }
          var booking = false;
          console.log('v 16:10');

        if($('#bookingEngine').length>0){
                    booking = true;
        }
            console.log(booking); // ALLWAYS LOGS false, when i know it's there

/*REST OF THE METHOD*/

然后我想,好吧,也许内容仍然不在窗口中,所以我在$(document).ready语句中包含了条件

      resize: function(x, y) {
        if (this.visible) {
          var size   = { x: $(window).width(),      y: $(window).height() };
          var scroll = { x: $(window).scrollLeft(), y: $(window).scrollTop() };
          var left   = (scroll.x + (size.x - (x + 14)) / 2);
          var top    = (scroll.y + (size.y - (y + 14)) / 2);
          console.log(size);
          if ($.browser.msie || ($.browser.mozilla && (parseFloat($.browser.version) < 1.9))) {
            y += 4;
          }
          var booking = false;
          console.log('v 16:10');
          $(document).ready(function(){
                if($(window).contents().find($('#bookingEngine')).length>0){
                    booking = true;
                }
          });

          console.log('Booking: '+booking);

/* REST OF THE METHOD */

所以问题是: ready函数不能在jquery方法中工作吗?

0 个答案:

没有答案