2010-11-12 62 views
2

這段代碼實際上有效,但並不完全如我所料。基本切換()底部到頂部的幻燈片問題

「.socialSlide」是在頁面底部設置的一個div,其特徵爲突出顯示的「標籤」錨點。其餘部分隱藏在底部。這個想法是通過單擊或懸停該鏈接來顯示或隱藏div。

// Adding the anchor link and hiding the rest of the div 
$('.socialSlide').prepend('<a href="#" class="ssOpen">Share</a>').css('bottom', '-77px'); 

並添加切換功能,以錨

/*add socialSlide toggle*/ 
$('.socialSlide a.ssOpen').toggle(function() { 
    $(this).parent().stop().animate({"bottom": "-25px"},{ queue:false, duration:900, easing: 'easeInOutQuint'}); 
    }, function() {  
    $(this).parent().stop().animate({"bottom": "70px"},{ queue:false, duration:900, easing: 'easeInOutQuint'}); 

正在發生的事情:

  1. 錨接收上點擊第一 動畫命令。精細。

  2. 另一次點擊錨鏈接應該 像以前一樣隱藏div,但它不會發生 。它至少 其他70像素。

  3. 在 錨第三點擊似乎正確地執行該第二功能 (),然後將第一 ,從那裏。

那麼,步驟2上可能發生了什麼?我錯過了什麼嗎?道歉,如果這聽起來太基礎。提前致謝。

+1

你可以在行動中顯示這個 - 無論是你自己的網站或http://jsfiddle.net/ – DaiYoukai 2010-11-12 04:04:36

回答

1

第二步應該隱藏div?那麼底部應該有負值:

$('.socialSlide a.ssOpen').toggle(function() { 
    $(this).parent().stop().animate({"bottom": "-25px"},{ queue:false, duration:900}); 
}, function() {  
    $(this).parent().stop().animate({"bottom": "-70px"},{ queue:false, duration:900}); 
}); 

但我不會用這個隱藏顯示項目,而不是包裝與另一個DIV和的slideToggle它的內容,如this