2013-10-15 41 views
0

我有一個我實際擁有的縮小版本,但它的方法相同,我努力解決的是當我點擊一個更多鏈接內我需要設置一個scrolltobottom底部函數,但我不能弄清楚如何做這個條件,所以如果我點擊它的最後一個LI做到這一點。有任何想法嗎?jQuery:讓最後一個點擊一個鏈接,並做一個動作或它

<ul> 
    <li> 
    <div class="truncated_text_wrapper"> 
     <div class="truncated_text" style="display: none;">sending this test message sending this test message sending... (<a data-action="expand_text" href="#">more</a>) 
     </div> 
     <div style="" class="complete_text">sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message (<a data-action="shrink_text" href="#">less</a>) 
     </div> 
     </div> 
     <a class="link" href="#">more</a> 
    </li> 
    <li> 
    <div class="truncated_text_wrapper"> 
     <div class="truncated_text" style="display: none;">sending this test message sending this test message sending... (<a data-action="expand_text" href="#">more</a>) 
     </div> 
     <div style="" class="complete_text">sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message (<a data-action="shrink_text" href="#">less</a>) 
     </div> 
     </div> 
     <a class="link" href="#">more</a> 
    </li> 
    <li> 
    <div class="truncated_text_wrapper"> 
     <div class="truncated_text" style="display: none;">sending this test message sending this test message sending... (<a data-action="expand_text" href="#">more</a>) 
     </div> 
     <div style="" class="complete_text">sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message (<a data-action="shrink_text" href="#">less</a>) 
     </div> 
     </div> 
     <a class="link" href="#">more</a> 
    </li> 
    <li> 
    <div class="truncated_text_wrapper"> 
     <div class="truncated_text" style="display: none;">sending this test message sending this test message sending... (<a data-action="expand_text" href="#">more</a>) 
     </div> 
     <div style="" class="complete_text">sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message sending this test message (<a data-action="shrink_text" href="#">less</a>) 
     </div> 
     </div> 
     <a class="link" href="#">more</a> 
    </li> 
</ul> 

的JS我曾經參與如下:

var carousel = setupCarousel(); 

    $(".truncated_text_wrapper .truncated_text a[data-action=expand_text]").live("click", function(){ 
    $(this).parents(".truncated_text").hide(); 
    $(this).parents(".truncated_text_wrapper").find(".complete_text").show(); 
     if($(this).siblings().length===0) { 
      carousel.scrollToBottom(); 
      console.log('moved'); 
     } 
     return false; 
    }); 

你會看到我試圖如果兄弟姐妹scrolltobottom - 我只是想行動,如果這是最後李越按鈕被點擊。

+7

我想你縮小你的問題太多了。你究竟想在這裏做什麼? –

+0

對不起清晨:)我已更新與JS我有什麼即時通訊理想尋找是添加一個if語句滾動到底部,如果它的最後一個點擊時,你點擊特定的更多鏈接 –

回答

0

你的意思是這樣的:

$('ul').find('li a').on('click', function(){ 
    window.scrollTo(0, document.scrollHeight); 
}); 

或者只有最後李:

$('ul').find('li:last-child a').on('click', function(){ 
    window.scrollTo(0, document.scrollHeight); 
}); 

或者動畫滾動到點擊的元素:

$('ul').find('li:last-child a').on('click', function(e){ 
    e.preventDefault() // this time you want the anchor to do nothing 
    var elem = this; 
    $("html, body").animate({ scrollTop: $(elem.href).offset().top }, 1000); 
}); 
+0

感謝Martijn,我更新與JS我有 - 我只需要一個if語句,如果它是最後一個li,並且只有當你點擊最後一次閱讀鏈接 –