詩を単語ごとに表示しています(lettering.jsとjQueryを使用しています。これはうまく機能しています。次に機能を追加します:テキストが画面に表示されたときにページを下にスクロールします。試しています:
div.lettering('words');
div.find('span').hide();
div.show().find('span').each(function(i) {
$(this).delay(delay * i).fadeIn(fadeIn);
var _this = $(this);
$('html, body').scrollTop(
_this.offset().top - $('html, body').offset().top + $('html, body').scrollTop()
);
});
また試した:
div.lettering('words');
div.find('span').hide();
div.show().find('span').each(function(i) {
$(this).delay(delay * i).fadeIn(fadeIn);
var _this = $(this);
$('html, body').animate({
scrollTop: _this.offset().top
}; 500);
});
しかし、ページはページの読み込み時にある位置までスクロールします。それだけです。私が使用している_this変数が正しくないように感じます。
私の目標を達成する方法はありますか?