0

私は苦労しているJavaScriptの本当に基本的なビットを持っています。これにより、ユーザーはリンクをクリックすると、ビューポートがページ内のそのポイントに移動します。これが私の現在のいじくり回しです:https ://tinker.io/8e585/16 。

ユーザーが「テスト2 」の下の画像^をクリックすると、下にスクロールして「テスト2 」内のテキストが同時に開くように機能させたいですか?

これに関するポインタに感謝します。

 

^<h3 class="head"><a href="javascript:slideonlyone('newboxes7');"><img src="/wp-content/themes/boilerplate/images/image_corner_btn_offstate.png" class="small" style="position:absolute;margin-left: 241px;margin-top: 128px;" /><img src="/wp-content/themes/boilerplate/images/sector-21.jpg"></a></h3>

4

2 に答える 2

2

$(this).scrollTop()関数を呼び出してscrollTopイベントを定義できます

$(this).scrollTop(function(){
    //your code to do both tasks
)};

それが役に立てば幸い :)

アップデート:

function slideonlyone(thechosenone) {
     $('.newboxes2').each(function(index) {
          if (this.id == thechosenone) {
                if($(this).is('.active') )
                   $(this).removeClass('active').slideUp(600);
              else 
              $(this).addClass('active').slideDown(200);
          }
          else              
               $(this).removeClass('active').slideUp(600);

         if($(this).is('.active') )
             jQuery(this).parent('.grid_4').children().find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_onstate.png');
         else
             jQuery(this).parent('.grid_4').children().find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_offstate.png');
     });
}

$('#box1 h2').click(function () {   
    $('html, body').animate({
         scrollTop: $('#box2').offset().top}, 'slow');
    slideonlyone(thechosenone);
    return false;
});
$('#box2 h2').click(function () {   
    $('html, body').animate({
         scrollTop: $('#box1').offset().top}, 'slow');
    slideonlyone(thechosenone);
    return false;
});
于 2013-01-25T14:59:00.217 に答える
0

答え:https : //tinker.io/8e585/19 :-D

基本的に使用し$("#box2 h3 a").click(function () {ました。

于 2013-01-26T06:12:47.820 に答える