2012-07-11 72 views
0

第二屆腳本後,它的後一個使用第一個腳本林有麻煩做兩個jQuery的腳本工作一個接一個

我試着用這個

$(document).ready(function() { 


$('div.frame ul#main li a').click(function(){ 

     var toLoad = $(this).attr('href')+' #content'; 
     $('#content').hide('fast',loadContent); 
     function loadContent() { 
      $('#content').load(toLoad,'',showNewContent()) 
     } 
     function showNewContent() { 
      $('#content').show('normal',hideLoader()); 
     } 
     function hideLoader() { 
      $('#load').fadeOut('normal'); 
     } 
     return false; 

    }); 

}); 

加載它加載後不工作頁面加載使用這一個

$(document).ready(function(e) { 


    var currentportfolio = $('div#slider ul li:first-child').addClass('show'); 
    var portfolio = $('div#slider ul li'); 
    $('div#slider ul li').not(':first').hide(); 


    $('.prev, .next').click(function() { 
    // Determine the direction, -1 is prev, 1 is next 
    var dir = $(this).hasClass('prev') ? -1 : 1; 
    // Get the li that is currently visible 
    var current = $('div#slider ul li:visible'); 

    // Get the element that should be shown next according to direction 
    var new_el = dir < 0 ? current.prev('li') : current.next('li'); 

    // If we've reached the end, select first/last depending on direction 
    if(new_el.size() == 0) { 
     new_el = $('div#slider ul li:'+(dir < 0 ? 'last' : 'first')); 
    } 

    // Hide them all.. 
    $('div#slider ul li').hide(); 
    // And show the new one 
    new_el.show(); 

    // Prevent the link from actually redirecting the browser somewhere 
    return false; 
}); 

}); 

Im新的jQuery。提前致謝。

+4

流行的觀點相反,你沒有在jQuery的寫這篇文章,您在Javascript寫的。 jQuery是用JavaScript編寫的DOM操作庫... – 2012-07-11 01:04:27

+3

@ElliotBonneville http://i.qkme.me/35p5ss.jpg – Fresheyeball 2012-07-11 01:05:33

+0

你還可以發佈與此一致的HTML嗎? – Daedalus 2012-07-11 01:06:54

回答

1

查閱.load的文檔。 jQuery提供了一個「回調」函數作爲.load函數的一部分。回調基本上是在.load完成後運行的。它看起來像你已經在使用。

http://api.jquery.com/load/

function showNewContent() { 
     $('#content').show('normal',hideLoader()); 
     additionalStuffToDoAfterLoad(); 
    } 

    function additionalStuffToDoAfterLoad(){ 
     //all the stuff in section 2 goes here. 
    } 
+0

+1。另外,你的頭像正在嚇跑我。 O.o – 2012-07-11 01:09:54

+2

@ElliotBonneville我會將你吸引到我眼中的空虛MUHAHHHAHHA! – Fresheyeball 2012-07-11 01:11:57