Cookies with a jquery class switcher?
I really can't figure out how to use cookies with this class switcher I got here
Jquery:
<script type="text/javascript">
$(document).ready(function(){
$("a.switch_thumb").toggle(function(){
$(this).addClass("swap");
$(".main").fadeOut("fast", function() {
$(this).fadeIn(300).addClass("main2");
});
}, function () {
$(this).addClass("swap");
$(".main2").fadeOut("fast", function() {
$(this).fadeIn(300).addClass("main3");
});
开发者_开发知识库
}, function () {
$(this).removeClass("swap");
$(".main").fadeOut("fast", function() {
$(this).fadeIn(300).removeClass("main3");
$(this).fadeIn(300).removeClass("main2");
});
});
</script>
Any tips?
It's a script that flips between 3 views (3 different backgrounds) and I want it to remember the last chosen background
It's not really clear what you're trying to do here without a link to the page; I'd suggest restructuring the code to be a single function called via the click method.
You can then call that function on document ready too switching on the cookie which you could set with the jQuery Cookie Plugin; therefore maintaining the current selection across different pages which I think is your intended functionality?
精彩评论