admin管理员组文章数量:1327961
I'm working on a project for a client built on Twitter Bootstrap. He wants to have different colour schemes that the user can select from. For example have a Red Colour Scheme and a Blue Colour Scheme that the user can change through a menu up the top.
Is there any plugins for jQuery (or anything else for that matter) that will do this? All it really has to do is load a different CSS file I suppose, how would you go about doing this?
I'm working on a project for a client built on Twitter Bootstrap. He wants to have different colour schemes that the user can select from. For example have a Red Colour Scheme and a Blue Colour Scheme that the user can change through a menu up the top.
Is there any plugins for jQuery (or anything else for that matter) that will do this? All it really has to do is load a different CSS file I suppose, how would you go about doing this?
Share Improve this question edited Nov 3, 2012 at 13:02 Sameera Thilakasiri 9,50810 gold badges53 silver badges87 bronze badges asked Oct 5, 2012 at 11:43 samturnersamturner 2,2235 gold badges26 silver badges31 bronze badges4 Answers
Reset to default 2Use Kickstrap. You can install themes from basically anywhere, make your own, includes themes from Bootswatch and it uses Less.js client-side to easily repile your changes each time.
Alright, since you want to load different themes...
You can use jQuery to load different stylesheets
<html>
<head>
<link rel="stylesheet" href="stylesheet.css" type="text/css" />
</head>
<body>
...
</html>
This could be a button click or another event that is triggered. So, what you would do is simply insert a new element into the head section of the page DOM. This can be done in a couple of lines of jQuery:
$(document).ready(function () {
$("a").click(function () {
$('head').append('<link rel="stylesheet" href="style2.css" type="text/css" />');
});
});
I hope this solves it...
I tested this on IE11, Chrome, Firefox and it works:
1.
<link id="theBoostrapTheme" type = "text/css" rel = "stylesheet" href = "Content/bootstrap-theme.min.css"/>
2.
<a role="menuitem" tabindex="-1" href="javaScript:void(0);" onclick="changeCurrentTheme('_Cerulean')">Cerulean</a>
Code:
function changeCurrentTheme(theNewThemeName) { $("#theBoostrapTheme").attr("href", "Content/bootstrap-theme.min" + theNewThemeName + ".css"); }
In this case the theme files other than the original were named like this: bootstrap-theme.min_ …. .css
. For example: bootstrap-theme.min_Cerulean.css
Changing the href of your style will, by itself, do nothing. The browser has already loaded your CSS and changing the HREF will not cause him to read the new file again.
Read the answer to this question, it might help you.
If a reload of the page is okay, you should probably do it on the server rather than through javascript by using some session value that defines what color scheme to use.
本文标签: javascriptSwitching between Twitter Bootstrap ThemesStack Overflow
版权声明:本文标题:javascript - Switching between Twitter Bootstrap Themes? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742223994a2435649.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论