Цитата | 1) RTFM Внутри callback функции this ссылается на DOM элемент, в который вставляются данные.
|
А мне надо сослаться на объект, из класса которого вызывается функция. Потому что JQurey.load заменяет контент в блоке, а мне надо к уже имеющимся в блоке блокам добавить загруженный блок.
Код
Код | // в $(document).ready(function() a = new scrollwindow($('#top100_girl'), 6)
//класс function scrollwindow(domscroll, allitem) { //class scrollwindow.prototype.line=$(domscroll).find('.line') this.arrow_prev=$(domscroll).find('.arrow_left') this.arrow_next=$(domscroll).find('.arrow_right') this.offset=0 this.nowitem=3 this.nitem=3 this.item_width=129+26 this.item_shag =31 this.ait=allitem scrollwindow.prototype.next = function() { alert(this.nowitem) //по клику ожидаю увидеть 3, но this тут почему-то обекту не сооветствует, выводит undefined см. 3-ю снизу строчку firstload=0 if (this.nowitem<allitem) { if (this.nowitem>=this.nitem) { firstload = this.nowitem-this.nitem+1 scrollwindow.prototype.load(firstload) } scrollwindow.prototype.move(1) if(this.nowitem+PRELOAD>this.nitem) { scrollwindow.prototype.load(this.nowitem+PRELOAD-this.nitem-firstload) } if(this.nowitem==allitem) { $(this.arrow_next).addClass('arrow_right_disable') } else if (this.nowitem==4) { $(this.arrow_prev).removeClass('arrow_left_disable') } } } scrollwindow.prototype.prev = function() { if(this.nowitem>3) { this.move(-1) } if(this.nowitem==3) { $(this.arrow_prev).addClass('arrow_left_disable') } else if (this.nowitem==allitem-1) { $(this.arrow_next).removeClass('arrow_right_disable') } } scrollwindow.prototype.load = function(nload) { if(typeof(nload)=='undefined') {nload=PRELOAD} i=this.nitem nload+=i for(i++; i<=nload && i <= allitem; i++) $.get('testajax/ajax'+i+'.html', scrollwindow.prototype.apploaded, 'html')// Загрузка HTML элемента } scrollwindow.prototype.apploaded = function (html) { alert(this.nowitem) // Должно вывести '3', но т.к. this здесь обьекту не соответствует, выводит undefined $(this.line).append(html) //здесь от этого не работает this.nitem++ } this.moveto=0 scrollwindow.prototype.move = function(to) { // to = -1 or 1 this.moveto=to scrollwindow.prototype.animation() this.nowitem+=to } this.timer=0 this.intervalref scrollwindow.prototype.animation = function() { if(this.timer==0) { this.intervalref=setInterval(scrollwindow.prototype.animation, 5) this.timer= this.item_width / this.item_shag } else { this.offset+= (this.item_shag)* -this.moveto; $(this.line).css('margin-left', this.offset + 'px') this.timer-- } if(this.timer==0) { clearInterval(this.intervalref) } }
$(this.arrow_prev).mousedown(scrollwindow.prototype.prev) $(this.arrow_next).mousedown(this.next) //здесь на стрелку пытаюсь навесить метод next() this.load() }
|
Добавлено @ 13:44 HTML, для которого код
Код | <div class="scroll scroll_right" id="top100_boy"> <div class="arrow_left arrow_left_disable"></div><div class="arrow_right"></div> <!-- стрелки --> <div class="frame"> <!-- у этого overflow:hidden --> <div class="line"> <!-- длинная полоса, которая должна ездить, показывая разных пользователей в блоке frame--> <div class="item"> <a href="" class="image"><img src="sample_user1.jpg" alt="фото"></a> <div class="desc"> <a href="#">Анастасия</a> <div>Москва</div> </div> </div> <div class="item"> <a href="" class="image"><img src="sample_user2.jpg" alt="фото"></a> <div class="desc"> <a href="#">Анастасия</a> <div>Москва</div> </div> </div> <div class="item"> <a href="" class="image"><img src="sample_user3.jpg" alt="фото"></a> <div class="desc"> <a href="#">Анастасия</a> <div>Москва</div> </div> </div> </div> </div> </div>
|
|