jquery的Theme和Theme Switcher使用小结


Posted in Javascript onSeptember 08, 2010

首先上一幅截图,效果不错吧:
jquery的Theme和Theme Switcher使用小结

一、引入jquery主题theme 
在head中引用jquery主题的CSS链接http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/themes/base/jquery-ui.css还有许多其他不同的主题:base, black-tie, blitzer, cupertino, dark-hive, dot-luv, eggplant, excite-bike, flick, hot-sneaks, humanity, le-frog, mint-choc, overcast, pepper-grinder, redmond, smoothness, south-street, start, sunny, swanky-purse, trontastic, ui-darkness, ui-lightness, vader。只要将上面链接中的base替换成主题名即可切换不同的主题。 

二、使用jquery主题theme 
给想要装饰的部分加上class,如:<a class="ui-state-default ui-corner-all" href="#">Nothing's gonna change my love for you</a> 表示默认的ui, corner-all表示圆滑四个角。

jquery的Theme和Theme Switcher使用小结 

三、增加hover的效果

jquery的Theme和Theme Switcher使用小结

这里需要使用jquery的脚本。首先在head中引入jquery库 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script> 
1.3表示1.3里面的最新版本,现在是1.3.2。 
然后手写脚本;

$(function(){$('.ui-state-default').hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});});

这样就实现了鼠标移到上方是改变样式的效果了。

四、使用Theme Switcher在前台更换主题
先引入库

<script type="text/javascript" src="http://jqueryui.com/themeroller/themeswitchertool/"></script>

,然后可以在页面任何地方加入层<div id="switcher">主题切换功能载入中...</div>,我习惯将这个switch的wikget做成apDiv层,方便挪动合适的位置。最后手写script激活这个层:
$('#switcher').themeswitcher();

jquery的Theme和Theme Switcher使用小结

五、使网页记住自己的主题 
每次更换主题,jquery都会写入cookie的,要使网页记住自己的主题,只需要提取这个cookie出来,并且刷新页面的css即可。 
把脚本写出来 

$(function(){if(theme==null) updateCSS("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css");else updateCSS("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/"+theme+"/jquery-ui.css");}) 
function updateCSS(locStr){var cssLink=$('<link href="'+locStr+'"type="text/css" rel="Stylesheet" class="ui-theme"/>');$("head").append(cssLink);if($("link.ui-theme").size()>3){$("link.ui-theme:first").remove();}}

最后页面代码大概是这样子的:
<?xml version="1.0" encoding="UTF-8" ?> 
<%@ page language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<style type="text/css"> 
#switcher { 
position:absolute; 
left: 564px; 
top: 20px; 
} 
</style> 
<script src="http://www.google.com/jsapi"></script> 
<script type="text/javascript">google.load("jquery","1.3.2");google.load("jqueryui","1.7.2");function OnLoad(){$('#switcher').html("");var theme=$.cookie('jquery-ui-theme');$(function(){if(theme==null) updateCSS("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css");else updateCSS("http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/"+theme+"/jquery-ui.css");});$(function(){$('.ui-state-default').hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});});$("#pic2").hide();$('#switcher').themeswitcher();}google.setOnLoadCallback(OnLoad);function updateCSS(locStr){var cssLink=$('<link href="'+locStr+'"type="text/css" rel="Stylesheet" class="ui-theme"/>');$("head").append(cssLink);if($("link.ui-theme").size()>3){$("link.ui-theme:first").remove();}} 
</script> 
<script type="text/javascript" src="http://jqueryui.com/themeroller/themeswitchertool/"></script> 
</script> 
<title></title> 
</head> 
<body> 
<div id="switcher">主题切换功能载入中...</div> 
<p><a class="ui-state-default ui-corner-all" href="http://mee-moo.googlecode.com/svn/trunk/resource/music/nothinggcmlfu.mp3">Nothing's gonna change my love for you</a></p> 
</body> 
</html>
Javascript 相关文章推荐
javascript实现复制与粘贴操作实例
Oct 16 Javascript
javascript遇到html5的一些表单属性
Jul 05 Javascript
js代码验证手机号码和电话号码是否合法
Jul 30 Javascript
js判断子窗体是否关闭的方法
Aug 11 Javascript
JQuery自适应窗口大小导航菜单附源码下载
Sep 01 Javascript
自定义Angular指令与jQuery实现的Bootstrap风格数据双向绑定的单选与多选下拉框
Dec 12 Javascript
Javascript 跨域知识详细介绍
Oct 30 Javascript
vue 开发一个按钮组件的示例代码
Mar 27 Javascript
JS中判断字符串存在和非空的方法
Sep 12 Javascript
vue-router懒加载速度缓慢问题及解决方法
Nov 25 Javascript
angular 实现同步验证器跨字段验证的方法
Apr 11 Javascript
Elementui表格组件+sortablejs实现行拖拽排序的示例代码
Aug 28 Javascript
复制小说文本时出现的随机乱码的去除方法
Sep 07 #Javascript
extjs grid设置某列背景颜色和字体颜色的实现方法
Sep 06 #Javascript
动态加载图片路径 保持JavaScript控件的相对独立性
Sep 06 #Javascript
Document对象内容集合(比较全)
Sep 06 #Javascript
Jquery优化效率 提升性能解决方案
Sep 06 #Javascript
jquery中this的使用说明
Sep 06 #Javascript
firefox下frameset取不到值的解决方法
Sep 06 #Javascript
You might like
解析:php调用MsSQL存储过程使用内置RETVAL获取过程中的return值
2013/07/03 PHP
php约瑟夫问题解决关于处死犯人的算法
2015/03/23 PHP
PHP中使用hidef扩展代替define提高性能
2015/04/09 PHP
laravel学习笔记之模型事件的几种用法示例
2017/08/15 PHP
新页面打开实际尺寸的图片
2006/08/25 Javascript
彻底搞懂JS无缝滚动代码
2007/01/03 Javascript
JQuery下关于$.Ready()的分析
2009/12/13 Javascript
在IE6下发生Internet Explorer cannot open the Internet site错误
2010/06/21 Javascript
JavaScript实现页面实时显示当前时间的简单实例
2013/07/20 Javascript
html页面显示年月日时分秒和星期几的两种方式
2013/08/20 Javascript
JavaScript通过this变量快速找出用户选中radio按钮的方法
2015/03/23 Javascript
JavaScript tab选项卡插件实例代码
2016/02/23 Javascript
对比分析Django的Q查询及AngularJS的Datatables分页插件
2017/02/07 Javascript
jQuery Jsonp跨域模拟搜索引擎
2017/06/17 jQuery
jquery单击文字或图片内容放大并居中显示
2017/06/23 jQuery
JavaScript反弹动画效果的实现代码
2017/07/13 Javascript
详解Nuxt.js中使用Element-UI填坑
2019/09/06 Javascript
详解Webpack抽离第三方类库以及common解决方案
2020/03/30 Javascript
Vue关于组件化开发知识点详解
2020/05/13 Javascript
Python定时发送消息的脚本:每天跟你女朋友说晚安
2018/10/21 Python
Python Numpy 控制台完全输出ndarray的实现
2020/02/19 Python
Python matplotlib修改默认字体的操作
2020/03/05 Python
Python定时从Mysql提取数据存入Redis的实现
2020/05/03 Python
什么是属性访问器
2015/10/26 面试题
中专毕业生的自我鉴定
2013/12/01 职场文书
执行力心得体会
2013/12/31 职场文书
实习单位接收函
2014/01/11 职场文书
大学生创业策划书
2014/02/02 职场文书
《最后的姿势》教学反思
2014/02/27 职场文书
家电业务员岗位职责
2014/03/10 职场文书
老公保证书范文
2014/04/29 职场文书
卫生系统先进事迹
2014/05/13 职场文书
数学复习课教学反思
2016/02/18 职场文书
导游词之河北滦平金山岭长城
2019/10/16 职场文书
Redis数据同步之redis shake的实现方法
2022/04/21 Redis
Web应用开发TypeScript使用详解
2022/05/25 Javascript