JQuery/PHP

Jquery adds one click color change function to the website

 Alibaba Cloud

The website often has such a function that users can click the corresponding color to adjust the color of the website. That is what we call the color matching function. Here's how to add the skin color matching function to the website.

section

Add a jquery cache cookie plug-in jquery. cookie. js; Place the following code above the</head>tag of the web page;

Want to be here? contact us bar
 Maker host

section

On the header file, add a default CSS file;

  1.  < link  href = "css/default.css"  rel = "stylesheet"  type = "text/css"  id = "cssfile"  / >

section

Add the following JS code to the header file for color matching switching and COOKIE writing;

  1.  < script  type = "text/javascript" >
  2.  // <! [CDATA[
  3.  $(function(){
  4.  var $li =$("#skin a");
  5.  $li.click(function(){
  6.  switchSkin( this.id );
  7.  });
  8.  var cookie_skin = $.cookie( "MyCssSkin");
  9.  if (cookie_skin) {
  10.  switchSkin( cookie_skin );
  11.  }
  12.  });
  13.  function switchSkin(skinName){
  14.  $("#"+skinName).addClass("selected").siblings().removeClass("selected");
  15.  //The current<li>element is selected
  16.  //Remove the selection of other peer<li>elements
  17.  $("#cssfile").attr("href","css/"+ skinName +".css");
  18.  //Set different skins
  19.  $.cookie( "MyCssSkin" , skinName , { path: '/', expires: 10 });
  20.  }
  21.  //]]>
  22.  < / script >

section

Make color matching switch button;

  1.  < div  class = "bt-yf" >< a  href = "javascript:void(0);"  id = "yifu"  class = "bt-btn-yf"  title = "Skin changing" > skin peeler < / a >< / div >

Add CSS style of button:

  1.  .bt-btn-yf { display : block ; width : 38px ; height : 38px ; background : #bababa  url ( ../images/yf.png )  no-repeat  50%  50% ; position : fixed ; z-index : nine thousand nine hundred and ninety-nine ; right : 10px ; bottom : 20% ; background-size : 80%  80% ; margin-top : 5px ; }
  2.  .show-yf { display : none ; position : fixed ; right : 10px ; top : 50% ; width : 50px ; z-index : nine hundred and ninety-nine ; text-align : center ; }
  3.  .show-yf a { display : block ; padding : 10px  zero ; height : 60px ; line-height : 40px ; }
  4.  .qey { background : #fff ; color : #333 }
  5.  .sey { background : #333 ; color : #fff ; }
  6.   
  7.  @media  ( max-width : 767px ) {
  8.  .show-yf { right : 10px ; top : 40% ; width : 30px ; z-index : nine hundred and ninety-nine ; text-align : center ; }
  9.  .show-yf a { display : block ; padding : 10px  zero ; height : 60px ; line-height : 40px ; }
  10.  }

section

Add the following code at the bottom of the page;

  1.  < div  class = "show-yf"  id = "skin" >
  2.  < a  href = "javascript:;"  id = "white"  class = "qey"  title = Light > light colour < / a >
  3.  < a  href = "javascript:;"  id = "black"  class = "sey"  title = Dark > Dark < / a >
  4.  < / div >
  5.  < script >
  6.  $("#yifu").click(
  7.  function(){
  8.  $(".show-yf").slideToggle();
  9.  });
  10.  < / script >

In this way, the skin switching function of a website is ready. Note that the file path in each code should be modified correctly. The following files should be added:

Jquery. cookie. js: Cookies plug-in

Default.css: default CSS, content can be empty

Black.css: the style of each element of the website under dark skin

White.css: the style of each element of the website under the light skin

Jquery adds one click color change function to the website

209 people have bought
View Demo Upgrade VIP Buy Now

Collection
fabulous ( zero )

Post reply

Hot selling template

Ashade - Works exhibition photo album WordPress Chinese theme
 LensNews

This site accepts WordPress/PbootCMS/DedeCMS, etc
System construction, imitation, development, customization and other services!