我正在一個網站上工作。當您點擊滑動到您想要的頁面的導航時,佈局是水平的。這一切都有效,但我然後爲每個頁面添加了一個調光器,因此當您在您選擇的頁面上時,其他調光器會變暗。我想知道是否有更好的方法來編寫這段代碼,目前它是每個頁面的一個函數,我想知道是否有辦法縮短這個時間。jquery - 水平頁面佈局 - 調光器
//When the link that triggers the message is clicked fade in overlay/msgbox
$(".test").click(function(){
$(".dimmerservices").fadeOut('slow', function() {
// Animation complete.
});
$(".dimmerother1").fadeIn('slow', function() {
// Animation complete.
});
return false;
});
//When the message box is closed, fade out
$(".close").click(function(){
$("#fuzz").fadeOut();
return false;
});
});
$(document).ready(function(){
//Adjust height of overlay to fill screen when page loads
$("#fuzz").css("height", $(document).height());
//When the link that triggers the message is clicked fade in overlay/msgbox
$(".casestud").click(function(){
$(".dimmercase").fadeOut('slow', function() {
// Animation complete.
});
$(".dimmerother2").fadeIn('slow', function() {
// Animation complete.
});
return false;
});
//When the message box is closed, fade out
$(".close").click(function(){
$("#fuzz").fadeOut();
return false;
});
});
$(document).ready(function(){
//Adjust height of overlay to fill screen when page loads
$("#fuzz").css("height", $(document).height());
//When the link that triggers the message is clicked fade in overlay/msgbox
$(".aboutclick").click(function(){
$(".dimmerabout").fadeOut('slow', function() {
// Animation complete.
});
$(".dimmerother3").fadeIn('slow', function() {
// Animation complete.
});
return false;
});
//When the message box is closed, fade out
$(".close").click(function(){
$("#fuzz").fadeOut();
return false;
});
});
$(document).ready(function(){
//Adjust height of overlay to fill screen when page loads
$("#fuzz").css("height", $(document).height());
//When the link that triggers the message is clicked fade in overlay/msgbox
$(".contactbutton").click(function(){
$(".dimmerend").fadeOut('slow', function() {
// Animation complete.
});
$(".dimmerother4").fadeIn('slow', function() {
// Animation complete.
});
return false;
});
//When the message box is closed, fade out
$(".close").click(function(){
$("#fuzz").fadeOut();
return false;
});
});
如果你可以做一個[的jsfiddle(http://jsfiddle.net),這將是巨大的,這樣我們就可以重構你的實際代碼向你展示它如何[幹](http://en.wikipedia.org/wiki/Don't_repeat_yourself)編輯。 –
http://jsfiddle.net/matthewrogers/uQH37/ –