2013-03-27 55 views
0

我想摺疊最後5行,在第一次點擊時從外部文件中填充內容。加載遠程內容後無法關閉div-jquery

我已經試過無數的事件,沒有運氣:

$(document).ready(function() { 
     $("li.span3 a").click(function (e) { 
      e.preventDefault(); 
      jQuery('html, body').animate({ scrollTop: jQuery('.content').offset().top -100 }, 'fast'); 
      $('.content').load(this.href).delay(2000); 
     }); 
     $("li.span3 a").click(function(){ 
      $('.content').unload(); 
      $('.content').addclass().css('height', '0px'); 
     }); 
    }); 

含量坐作爲目標網頁上的空div,對於要加載in.to

+0

你可以創建一個http://jsfiddle.net來顯示你的問題 – 2013-03-27 09:56:18

+0

你想再次單擊相同的元素來卸載內容嗎? – Pete 2013-03-27 09:58:13

+0

基本上是關閉或隱藏div到原始,不可見狀態。 Theres基本上是縮略圖圖像,一旦點擊其中一個圖標,其上方的一個部分將展開更詳細的點擊相應的圖像。 – lxm7 2013-03-27 09:59:58

回答

1

也許這個作品的內容您?

var $content = $('.content'); 

$(".span3").on('click', 'a', function (e) { 
    e.preventDefault(); 

    if($content.hasClass('loaded') { 
     $content.hide().removeClass('loaded'); 
    } else { 
     $('html, body').animate({ scrollTop: $content.offset().top -100 }, 'fast'); 
     $content.load(this.href).show().addClass('loaded'); 
    } 
}); 
+0

Lifesaver , 謝謝!我現在只需要弄清楚爲什麼每次點擊時滾動都會沿着頁面向下遞增。 – lxm7 2013-03-27 10:26:57