jquery cookie plugin for easy switching of background colors

Source: Internet
Author: User

<! DOCTYPE html>

<meta charset= "UTF-8" >

<title> Change background color </title>

<style type= "Text/css" >

#bg {Width:90%;height:500px;background:rgba (0,0,0,.2);p Osition:fixed;bottom:10px;left:0;right:0;margin:auto; display:none;border:5px solid #fff;}

. close{width:30px;height:30px;border:2ps Solid;line-height:30px;text-align:center;color: #fff; background: #000; position:absolute;right:0;top:0;font-size:25px;}

. color{width:200px;height:100px;border:1px solid #fff; float:left;margin:20px 35px;line-height:100px;text-align: Center;color: #fff; font-size:30px;}

</style>

<script src= "Jquery-1.12.4.js" ></script>

<script src= "Jquery.cookie.js" ></script>

<script type= "Text/javascript" >

$ (function () {

var bgcolor = $.cookie (' bgcolor '); Read the background color from the cookie

if (bgcolor) {

Document.body.style.backgroundColor = bgcolor; Show colors that already exist in the cookie

$ (' #bg '). CSS (' backgroundcolor ', ' Rgba (255,255,255,.7) '); Change the div background color with the BG ID to translucent white

}

$ (' #btn '). On (' click ', function () {

$ (' #bg '). Show ();

});

$ ('. Close '). On (' click ', function () {

$ (' #bg '). Hide ();

});

Gets the element with the class color and sets the background color

$ ('. Color '). each (function (index,element) {

var bgcolor = $ (Element). text ();

$ (this). CSS (' backgroundcolor ', bgcolor);

$ (Element). On (' click ', function () {

Document.body.style.backgroundColor = bgcolor;

$.cookie (' bgcolor ', bgcolor,{' expires ': ' Path ': '/'});

});

});

});

</script>

<body>

<button id= "BTN" > Toggle Skin </button>

<div id= "BG" >

<span class= "Color" >green</span>

<span class= "Color" >red</span>

<span class= "Color" >yellow</span>

<span class= "Color" >blue</span>

<span class= "Color" >lightgreen</span>

<span class= "Color" >pink</span>

<span class= "Color" >orange</span>

<span class= "Color" >gold</span>

<span class= "Color" >purple</span>

<strong class= "Close" >x</strong>

</div>

</body>


This article is from the "11996687" blog, please be sure to keep this source http://12006687.blog.51cto.com/11996687/1862133

jquery cookie plugin for easy switching of background colors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.