JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" class="switch_thumb">Switch Thumb</a>
<div class="selecter">
<div class="selecterBtns">
<ul class="nolist">
<li><a href="#" rel="test1" class="active">Test1</a></li>
<li><a href="#" rel="test2">Test2</a></li>
<li><a href="#" rel="test3">Test3</a></li>
</ul>
</div>
<div class="selecterContent">
<ul class="display">
<li>Projet1</li>
<li>Projet2</li>
<li>…</li>
</ul>
</div>
</div>
CSS
ul {
background-color : #aaf;
}
ul.thumb_view {
background-color : #faa;
}
JavaScript
jQuery.cookie = function (key, value, options) {
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options);
if (value === null || value === undefined) {
options.expires = -1;
}
if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}
value = String(value);
return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '',
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
$(document).ready(function(){
if($.cookie("button")=="thumb_view"){
$('ul.display').addClass($.cookie("button"));
$("a.switch_thumb").addClass("swap");
}else{
$('ul.display').removeClass($.cookie("button"));
$("a.switch_thumb").removeClass("swap");
}
var name="button";
$("a.switch_thumb").click(function(){
if($.cookie(name)!="thumb_view") {
alert(1);
$(this).addClass("swap");
$("ul.display").fadeOut("fast", function() {
$(this).fadeIn("fast").addClass("thumb_view");
});
$.cookie(name, "thumb_view");
}
else {
alert(2);
$(this).removeClass("swap");
$("ul.display").fadeOut("fast", function() {
$(this).fadeIn("fast").removeClass("thumb_view");
});
$.cookie(name, "not_thumb_view");
}
});
});