2013-05-14 3 views
0

Я пытаюсь немного изменить плагин, вот функция Prototype, я отметил, какие строки я добавил.jQuery - this.option становится неопределенным в функции загрузки

ОК, поэтому моя проблема возникает внутри функции img-load, которую я добавил. Я окружил старый код одним, чтобы убедиться, что сценарий ждет, пока изображение не загрузится. Проблема заключается в том, что «это» внутри функции загрузки не связано с внешней. Я попытался дать функции загрузки параметр, но, видимо, он не работает, или я делаю что-то неправильно.

Знаете ли вы простой способ сортировки наследования «это»? Я не знаю, что еще делать.

Plugin.prototype._fade = function(number) { 
    var $element, currentSlide, next, slidesControl, value, 
    _this = this; 
    $element = $(this.element); 
    this.data = $.data(this); 
    if (!this.data.animating && number !== this.data.current + 1) { 
    $.data(this, "animating", true); 
    currentSlide = this.data.current; 
    if (number) { 
     number = number - 1; 
     value = number > currentSlide ? 1 : -1; 
     next = number; 
    } else { 
     value = this.data.direction === "next" ? 1 : -1; 
     next = currentSlide + value; 
    } 
    if (next === -1) { 
     next = this.data.total - 1; 
    } 
    if (next === this.data.total) { 
     next = 0; 
    } 

    this._setActive(next); 
    slidesControl = $(".slidesjs-control", $element); 



    var nxtImg = $(slidesControl.children(":eq(" + next + ")")).find("img:eq(0)"); // added 
    if (nxtImg.attr("longdesc") !== undefined) { // added 
     nxtImg.attr("src", nxtImg.attr("longdesc")); // added 
     nxtImg.removeAttr("longdesc"); // added 
    } // added 


    nxtImg.load(function(){ // added 
     slidesControl.children(":eq(" + next + ")").css({ 
     display: "block", 
     left: 0, 
     zIndex: 0 
     }); 
     this.options.callback.start(currentSlide + 1); 
     if (this.options.effect.fade.crossfade) { 
     return slidesControl.children(":eq(" + this.data.current + ")").stop().fadeOut(this.options.effect.fade.speed, (function() { 
      slidesControl.children(":eq(" + next + ")").css({ 
      zIndex: 10 
      }); 
      $.data(_this, "animating", false); 
      $.data(_this, "current", next); 
      return _this.options.callback.complete(next + 1); 
     })); 
     } else { 
     slidesControl.children(":eq(" + next + ")").css({ 
      display: "none" 
     }); 
     return slidesControl.children(":eq(" + currentSlide + ")").stop().fadeOut(this.options.effect.fade.speed, (function() { 
      slidesControl.children(":eq(" + next + ")").stop().fadeIn(_this.options.effect.fade.speed).css({ 
      zIndex: 10 
      }); 
      $.data(_this, "animating", false); 
      $.data(_this, "current", next); 
      return _this.options.callback.complete(next + 1); 
     })); 
     } 
    }); // added 



    } 
}; 

ответ

1

Вы захватываете это в переменной закрытия «_this». Разве это не работает?

+0

На самом деле вы правы! Я только что обменял это с этим, и теперь все работает. Просто так, но я не мог понять это сам. Благодаря! – user828591