网站转变风格的css变化
网站换肤,是一个比较老的话题了,理论很清晰,就是要根据js 来变换文件加载的css文件,根据需求来加载不同的css文件,有了这个基础就很明确要怎么做了,但是实际上还要记录当前用户的cookie 保证用户在下次登录的时候,能够使用之前的皮肤,这也就用到了cookie 和本地存储了 这就要看需要怎么样的需求了,下面这段代码 ,可以说直接扒下来就可以用,因为项目中用到了iframe,所以也就顾及到了iframe的css样式的引入 。
##title=css4
<link rel="stylesheet" title=css4 type="text/css" href="$request.contextPath/plugins/jquery-ui-custom/css/custom-theme/jquery-ui-1.9.2.custom-flat4.css" charset="utf-8"/>
<link rel="stylesheet" title=css4 type="text/css" href="$request.contextPath/css/main-flat4.css"/>
<link rel="stylesheet" title=css4 type="text/css" href="$request.contextPath/css/dashboard-flat4.css" />
##title=css1 默认
<link rel="stylesheet" title=css1 type="text/css" href="$request.contextPath/plugins/jquery-ui-custom/css/custom-theme/jquery-ui-1.9.2.custom-flat3.css" charset="utf-8"/>
<link rel="stylesheet" title=css1 type="text/css" href="$request.contextPath/css/main-flat3.css" />
<link rel="stylesheet" title=css1 type="text/css" href="$request.contextPath/css/dashboard-flat3.css"/> #if($cssFiles)
#foreach($css in $cssFiles)
<link rel="stylesheet" type="text/css" href="$request.contextPath/$css"/>
#end
#end
<script type="text/javascript" src="$request.contextPath/plugins/jquery-ui-custom/js/jquery-1.8.3.js"></script>
<script type="text/javascript"> $(document).ready(function(){
// $('.skin').click(function(event){
// event.stopPropagation();
// $('.skin-content').slideToggle("slow");
// });
// $(document).click(function(){
// $('.skin-content').slideUp("slow");
// });
$('.styleswitch').click(function(){
switchStylestyle(this.getAttribute("rel"));
//alert(this.getAttribute("rel"));
return false;
});
var c = readCookie('style');
if (c) switchStylestyle(c);
}); function switchStylestyle(styleName)
{
$('link[rel*=style][title]').each(function(i)
{
this.disabled = true;
if (this.getAttribute('title') == styleName) this.disabled = false;
});
var f=$('iframe');
f.contents().find('link[rel*=style][title]').each(function(i)
{
this.disabled = true;
if (this.getAttribute('title') == styleName) this.disabled = false;
});
var f=$('iframe').contents().find('iframe');
f.contents().find('link[rel*=style][title]').each(function(i)
{
this.disabled = true;
if (this.getAttribute('title') == styleName) this.disabled = false;
});
createCookie('style', styleName, 365);
} function createCookie(name,value,days)
{
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
} function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
} function eraseCookie(name)
{
createCookie(name,"",-1);
}
// /cookie functions </script>
<!--<script type="text/javascript">-->
//var currentStyle = localStorage.getItem('curSDAPStyle') || 'css1';
//$(function(){
// $('.skin').click(function(event){
// event.stopPropagation();
// $('.skin-content').slideToggle("slow");
// });
// $(document).click(function(){
// $('.skin-content').slideUp("slow");
// });
// $('.styleswitch').click(function(){
// switchStyle(this.getAttribute("rel"));
// //alert(this.getAttribute("rel"));
// return false;
// });
//
//
// if (currentStyle) {
// switchStyle(currentStyle);
// if ($('iframe').length) {
// $('iframe').each(function () {
// $(this).load(function () {
// var currentStyle = localStorage.getItem('curSDAPStyle') || 'css1';
// switchStyle(currentStyle);
// if ($(this).contents().find('iframe').length) {
// $(this).contents().find('iframe').each(function () {
// $(this).load(function () {
// var currentStyle = localStorage.getItem('curSDAPStyle') || 'css1';
// switchStyle(currentStyle);
// });
// });
// }
// });
// });
// }
// }
//});
//function switchStyle(name) {
// var _loop = function (el) {
// if (el.find('link[rel*=style][title]').length) {
// el.find('link[rel*=style][title]').each(function () {
// this.disabled = true;
// if (this.getAttribute('title') == name) this.disabled = false;
// });
// } else {
// _render(el);
// }
// }, _render = function (el, type) {
// var curEl = type ? el : el.contents();
// if (curEl.find('link[rel*=style][title]').length) {
// _loop(curEl);
// } else {
// el.load(function () {
// _loop(curEl);
// });
// }
// };
// localStorage.setItem('curSDAPStyle', name);
// currentStyle = name;
// _render($(document), 'root');
// if ($('iframe').length) {
// $('iframe').each(function () {
// _render($(this));
// if ($(this).contents().find('iframe').length) {
// $(this).contents().find('iframe').each(function () {
// _render($(this));
// });
// }
// });
// }
//}
<!--</script>-->
两套样式,主要依据了link标签的title 和disabled 这两个属性来进行控制的,cookie相关的代码几乎可以不用动了,要注意的就是点击事件来分别控制不同的代码引入就好了。。
还可以进入个人博客:www.jishubar.cn
网站转变风格的css变化的更多相关文章
- 转载网易博客:整理各大网站让网站变灰的css代码
2013-07-21 15:06:47 北京时间2013年4月20日8时02分四川省雅安市芦山县(北纬30.3,东经103.0)发生7.0级地震.震源深度13公里.各大网站将其网站变灰,本人整理了下部 ...
- 豆瓣移动端风格的css命名方法与学习
在CSS取名相对于刚入门来说是最头疼的事情,往往取一个可读性的名字相对以后的代码风格还是很重要的. 在配合团队方面一个好的类名可以帮助同事来理解,增加团队之间的效率有着很大的意义. 豆瓣的前段相对其他 ...
- web前端学习笔记(CSS变化宽度布局)
一.“1-2-1”单列变宽布局: 对于变宽度的布局,首先要使内容的整体宽度随浏览器窗口宽度的变化而变化.因此中间的container容器中的左右两列的总宽度也会变化,这样就会产生不同的情况.这两列是按 ...
- css变化代码
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...
- 网站项目所有js css无法引用问题解决方案
网站页面中的所有js css引用失效,路径确保正确,但是浏览器就是报找不到引用.仔细查找发现问题所在: 报错信息很详细了,就是.NET Framework 版本不同导致.同时也提供了两个解决方案:将. ...
- 如何扒取一个网站的HTML和CSS源码
一个好的前端开发,当看到一个很炫的页面的时候会本着学习的心态,想知道网站的源码.以下内容只是为了大家更好的学习,拒绝抄袭,支持正版. 1 首先我们要有一个chrome浏览器 2 在本地创建相关文件夹 ...
- 【使用DIV+CSS重写网站首页案例】CSS选择器
使用表格<table></table>对网站首页进行布局有缺陷,不能拖动版块,不灵活. DIV Div是一个html的标签,单独使用没有意义,必须结合CSS使用: 是一个块级元 ...
- CSS变化、过渡与动画
CSS变换用于在空间中移动物体,而CSS过渡和CSS关键帧动画用于控制元素随时间推移的变化. 变换.过渡和关键帧动画的规范仍然在制定中.尽管如此,其中大多数特性已经在常用浏览器中实现了. 1.二维变换 ...
- 网站性能优化之CSS无图片技术:三角形
1.使用CSS无图片技术,可以总结得到以下三个优点: 减少请求资源的大小: 减少http的请求个数: 提高可维护性. 一.CSS无图片技术,微博中有哪些实际应用呢? 通过上面的展示,我们可以看到,无图 ...
随机推荐
- 压缩tar命令
option z表示压缩,所以才有后面的.gz, c表示创建这个压缩包,v是可视,能看到其打包和压缩的过程,f表示文件 zcvf 命令格式为 先压缩后跟压缩的目录 tar zcvf /home/xia ...
- 【视频教程】一步步将AppBox升级到Pro版
本系列教程分为上中下三部分,通过视频的形式讲解如何将基于FineUI(开源版)的AppBox v6.0一步一步升级FineUIPro(基础版). [视频教程]一步步将AppBox升级到Pro版(上)主 ...
- windows系统php配置redis
网上各种找教程各种不行,最后东拼西凑的终于把redis弄出来了. PHP版本:7.1.0: Redis版本:3.2.10: Windows版本:Windows7: 一.Windows下安装Redis ...
- openstack-ocata-网络服务5
一. 网络服务概述 Networking(neutron),允许创建.插入接口设备,这些设备由其他的OpenStack服务管理.插件式的实现可以容纳不同的网络设备和软件,为OpenStack架构与部署 ...
- Xmind8 Pro安装教程 Windows
xmind是一款优秀的思维导图制作软件,这一点相信不用太多解释. 尤其作为测试人员导出测试用例为excel极其方便.网上xmind的破解方法加自己琢磨,重新整理了破解步骤. 亲测可以永久激活截止2 ...
- Java Web项目(Extjs)报错八
1.Java Web项目(Extjs)报错八 具体报错如下: org.springframework.dao.DataIntegrityViolationException: Could not ex ...
- 使用Gulp进行代码压缩的步骤以及配置
一.安装步骤 1.首先确定是否安装了node.js,如果未安装,请先安装node.js: 2.确定是否安装了包管理工具npm,如未安装请安装:npm install npm -g: 3.安装gulp: ...
- CF AIM Tech Round 3 (Div. 2) D - Recover the String
模拟 首先可以求出 0 和 1 的个数 之后按照01 10 的个数贪心安排 细节太多 错的都要哭了 #include<bits/stdc++.h> using namespace std; ...
- 简单bfs(hdu2612)
#include<stdio.h>#include<string.h>#include<queue>#define INF 0x3f3f3f3fusing name ...
- eclipse:An internal error occurred during: "Build Project". GC overhead limit exceeded
在使用Eclipse的Build Project功能时,提示以下错误: An internal error occurred during: "Build Project". GC ...