我有两个准备好的函数()脚本,如何将它结合起来保存在头文件中...有人重新排列代码来帮助我,,, 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 :(得分:1)
我不确定我理解你在问什么,但是如果你想知道如何将代码减少到一个就绪块,那么将每个就绪块中的代码放入它自己的函数中(没有就绪块)。然后,有一个只调用这两个函数的就绪块。
只需制作一个准备好的块:
$(document).ready(function() {
Init1();
Init2();
});
function Init1() {
// copy code here
}
function Init2() {
// copy code here
}
然后,将现有的就绪块移动到名为Init1()
和Init2()
的函数中(不带$(document).ready
)。我假设您可以自己将代码复制粘贴到正确的函数中,因为您知道什么比我更好。
答案 1 :(得分: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'
});