<! 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