- Fórum
- /
- Clube do Desenvolvedor
- /
- Clube do WebDesigner
- /
- Alternar duas folha de estilo com apenas um link
Alternar duas folha de estilo com apenas um link
- angelorocha
- Autor do Tópico
- Offline
- JCB! Estagiário
Menos
Mais
11 anos 9 meses atrás #75813
por angelorocha
[color=#4080FF:2a1pn4zc][i:2a1pn4zc][b:2a1pn4zc]Angelo Rocha
[size=85:2a1pn4zc][url:2a1pn4zc]http://www.angelorocha.com.br[/url:2a1pn4zc] | [url:2a1pn4zc]http://labs.angelorocha.com.br[/url:2a1pn4zc][/size:2a1pn4zc][/b:2a1pn4zc][/i:2a1pn4zc][/color:2a1pn4zc]
[color=#4080FF:2a1pn4zc][i:2a1pn4zc]Se, a princípio, a ideia não parecer absurda, então ela não vale apena.[/i:2a1pn4zc]
[b:2a1pn4zc]Albert Einstein [/b:2a1pn4zc][/color:2a1pn4zc]
angelorocha replied the topic: Re: Alternar duas folha de estilo com apenas um link
Tem algum problema, algum conflito de biblioteca, o codigo esta funcionando, vejam o arquivo que criei:
Index.html:
style.css:
stylealt.css:
js.js:
Versão do jQuery: jQuery 1.4.3
Agora é só enxugar meu template, resolvido!
Vlw.
Index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="style.css" title="1">
<link rel="alternate stylesheet" type="text/css" href="stylealt.css" title="2">
<script type="text/javascript" src="jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<li id="click"><a href="#">Teste</a></li>
</body>
</html>
style.css:
body{background:#333}
stylealt.css:
body{background:#CCC}
js.js:
$(document).ready(function() {
if($.cookie("contrast-bar")) {setActiveStyleSheet($.cookie("contrast-bar"));}
$('#click a').click(function(e) {
e.preventDefault();
if ( getActiveStyleSheet() == '1') {
setActiveStyleSheet('2');
} else {
setActiveStyleSheet('1');
}
});
});
function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
$.cookie("contrast-bar",title, {expires: 365, path: '/'});
}
function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return null;
}
function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) return a.getAttribute("title");
}
return null;
}
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};// JavaScript Document
Versão do jQuery: jQuery 1.4.3
Agora é só enxugar meu template, resolvido!
Vlw.
[color=#4080FF:2a1pn4zc][i:2a1pn4zc][b:2a1pn4zc]Angelo Rocha
[size=85:2a1pn4zc][url:2a1pn4zc]http://www.angelorocha.com.br[/url:2a1pn4zc] | [url:2a1pn4zc]http://labs.angelorocha.com.br[/url:2a1pn4zc][/size:2a1pn4zc][/b:2a1pn4zc][/i:2a1pn4zc][/color:2a1pn4zc]
[color=#4080FF:2a1pn4zc][i:2a1pn4zc]Se, a princípio, a ideia não parecer absurda, então ela não vale apena.[/i:2a1pn4zc]
[b:2a1pn4zc]Albert Einstein [/b:2a1pn4zc][/color:2a1pn4zc]
Please Entrar ou Registrar to join the conversation.
- Mexica
- Offline
- JCB! Junior
Menos
Mais
- Postagens: 78
- Obrigados Recebidos: 0