我編寫了一個代碼,我在其中調用jQuery.noConflict();多次。 如何減少jQuery.noConflict();存在,因爲我認爲這是不好的,該語句重複幾次減少Jquery noConflict的存在
$glob = jQuery.noConflict();
/* functions to run when content loads */
$glob(document).ready(function(){
var ht = $glob(window).height();
$glob('.content').css({
'height': ht,
'min-height': ht
});
$glob('#page').css({
'top':-ht
});
});
/* functions to run when page loads */
function animateHorizontal2id(id,msg){ //the id to animate, the easing type
var $a = jQuery.noConflict(); // defined to remove jquery conflict error
var animSpeed=2000; //set animation speed
var page= $a("#page"); //define the page to move
var ht = $a(window).height();
//do the animation
var archPos = $a(id).position().left;
$a('#architecture').css({
'left': archPos
});
page.stop().animate({"left": -($a(id).position().left)}, animSpeed
);
$a('#page').css({
'top': -ht
});
//}
}
function animateVertical2id(id,msg) {
var $arct = jQuery.noConflict(); // defined to remove jquery conflict error
var animSpeed=2000; //set animation speed
var page= $arct("#page"); //define the page to move
//do the animation
page.stop().animate({"top": -($arct(id).position().top)}, animSpeed);
}
function animate2Home(id,msg) {
var $home = jQuery.noConflict(); // defined to remove jquery conflict error
var archPos = $home(id).position().left;
var ht = $home(window).height();
$home('#page').css({
'top': -ht
});
$home('#architecture').css({
'left': archPos
});
var animSpeed=2000; //set animation speed
var page= $home("#page"); //define the page to move
//do the animation
page.stop().animate({"left": -($home(id).position().left)}, animSpeed);
}
應該不會出現任何需要保持重新定義它,只需在任何地方使用$ glob。我真的不明白爲什麼每次都將它重新定義爲不同的變量名稱,這太過撲朔迷離了! – RobMasters
它在定義的函數中不起作用 –