2010-08-16 16 views
1

我想在用户使用jQuery UI Themeselector更改页面主题时更改主体背景颜色。如何通过ThemeSelector更改背景颜色以匹配jQuery UI主题?

我已经试过这

function updateBodyBackground() { 
    $("body").css('background-color', $('.ui-widget-header:first").css("background-color") + ' !important;'); 
} 

然后我把它的文件准备(以设置初始主题背景)和我将它设置为这样的ThemeSelector OnClose事件;

$function() { 
    updateBodyBackground(); 
    $('#switcher').themeswitcher({ expires: 365, path: '/', loadTheme: "sunny", onClose: updateBodyBackground }); 
} 

在Firefox中没有做任何事情,似乎是Chrome上的一个变化,选择器在IE8中似乎不起作用。

有关如何更改背景以更好地匹配选定的jQuery UI主题的任何建议?

谢谢!

回答

0

巴吉修复使用超时...

查找功能updateCSS()themeswitchertool.js

内部之后 $( “头”)追加(cssLink)。

添加下面的线增加超时,如果它仍然无法正常工作......

插入 的setTimeout(“$( '主体'),CSS( '背景色',$(”。 ui-widget-header:first')。css('background-color'))“,2000);

0

你必须在你的js错误(使用的“,而不是”):

$('.ui-widget-header:first") 

应该是:

$('.ui-widget-header:first') 

但是我发现,这个工程没有必要投入Themeswitchertool。 .js,将setTimeout降到500,所以它变化更快。

function updateBodyBackground() {setTimeout("$('body').css('background-color', $('.ui-widget-header:first').css('background-color'))", 500); 
} 

$('#switcher').themeswitcher({ expires: 365, path: '/', loadTheme: "sunny", onClose: updateBodyBackground }); 
1

更好的方法是不使用计时器,只是我们ËjQueryUI的CSS类与背景色您寻找的一个,在我来说,我喜欢通过选择背景色:ui-state-hover

<div id= "main_background" class= "ui-state-hover"> 
// Your Content 
</div> 

由于id过的游乐设施都class设置,使用您的id删除或更改ui-state-hover使用的任何不良设置,例如背景图像:

#main_background { 
    position: relative; 
    top: 0px; 
    left: 0px; 
    width: 800px; 
    height: 742px; 
    margin: 0px; 
    border: 0px; 
    padding: 5px; 
    background-image:none; // kills the background url (image) that ui-state-hover sets 
} 
相关问题