2011-07-20 53 views
-1

我有兩個現成的功能()腳本,如何結合本保持頭file..can有人重新安排代碼,以幫助我,,, pllz腳本錯誤就緒函數()?

1)

<script type="text/javascript"> 

$(document).ready(function() { 

    //Get the height of the first item 
    $('#mask').css({'height':$('#panel-1').height()}); 

    //Calculate the total width - sum of all sub-panels width 
    //Width is generated according to the width of #mask * total of sub-panels 
    $('#panel').width(parseInt($('#mask').width() * $('#panel div').length)); 

    //Set the sub-panel width according to the #mask width (width of #mask and sub-panel must be same) 
    $('#panel div').width($('#mask').width()); 

    //Get all the links with rel as panel 
    $('a[rel=panel]').click(function() { 

     //Get the height of the sub-panel 
     var panelheight = $($(this).attr('href')).height(); 

     //Set class for the selected item 
     $('a[rel=panel]').removeClass('selected'); 
     $(this).addClass('selected'); 

     //Resize the height 
     $('#mask').animate({'height':panelheight},{queue:false, duration:500});   

     //Scroll to the correct panel, the panel id is grabbed from the href attribute of the anchor 
     $('#mask').scrollTo($(this).attr('href'), 800);  

     //Discard the link default behavior 
     return false; 
    }); 

}); 
</script> 

2)

<script type="text/javascript"> 
$(document).ready(
     function(){ 
      $('#testim').innerfade({ 
       animationtype: 'slide', 
       speed: 750, 
       timeout: 4000, 
       type: 'random', 
       containerheight: '102px' 
      }); 

    }); 

    //Get the height of the first item 
    $('#mask').css({'height':$('#panel-1').height()}); 

    //Calculate the total width - sum of all sub-panels width 
    //Width is generated according to the width of #mask * total of sub-panels 
    $('#panel').width(parseInt($('#mask').width() * $('#panel div').length)); 

    //Set the sub-panel width according to the #mask width (width of #mask and sub-panel must be same) 
    $('#panel div').width($('#mask').width()); 

    //Get all the links with rel as panel 
    $('a[rel=panel]').click(function() { 

     //Get the height of the sub-panel 
     var panelheight = $($(this).attr('href')).height(); 

     //Set class for the selected item 
     $('a[rel=panel]').removeClass('selected'); 
     $(this).addClass('selected'); 

     //Resize the height 
     $('#mask').animate({'height':panelheight},{queue:false, duration:500});   

     //Scroll to the correct panel, the panel id is grabbed from the href attribute of the anchor 
     $('#mask').scrollTo($(this).attr('href'), 800);  

     //Discard the link default behavior 
     return false; 
    }); 

}); 
</script> 

當我保持這樣一個progoram運行時,一個不,,如何解決,,,,

+0

這是jQuery的? – mschonaker

+0

請讓你的問題更清楚。 –

回答

1

我不知道我知道你要問什麼,但如果你想知道如何將你的代碼減少到一個就緒塊,然後把每個就緒塊的代碼放到它自己的函數中(沒有就緒塊)。然後,有一個準備好的塊,只是調用這兩個函數。

只是要一個現成塊:

$(document).ready(function() { 
    Init1(); 
    Init2(); 
}); 

function Init1() { 
    // copy code here 
} 

function Init2() { 
    // copy code here 
} 

然後,移動現有的準備塊成稱爲Init1()Init2()功能(不$(document).ready)。我想你可以複製的代碼粘貼到自己正確的功能你知道去哪裏好於一

+0

是的,,,我喜歡在一個就緒塊中調用兩個函數,你可以重新排列代碼... – besto

+0

我給我的答案添加了一個例子。 – jfriend00

+0

對不起,我完全不熟悉java腳本代碼...我不知道保留這個,如果你安排代碼它會有幫助嗎? – besto

0
$(document).ready(
     function(){ <<<<<<<<<<< delete 
      $('#testim').innerfade({ 
       animationtype: 'slide', 
       speed: 750, 
       timeout: 4000, 
       type: 'random', 
       containerheight: '102px' 
      }); 

    }); <<<<<<<<< delete 

使它看起來像這樣

$(document).ready(
    $('#testim').innerfade({ 
     animationtype: 'slide', 
     speed: 750, 
     timeout: 4000, 
     type: 'random', 
     containerheight: '102px' 
    }); 
相關問題