您好,欢迎来到模板无忧!
登录
注册
收藏
搜索
地图
帮助
模板无忧
网页特效
网页模板
CMS模板
PPT模板
简历模板
网页特效
视频教程
网页图标
字体下载
CMS教程
DivCss
网站制作
网站运营
网络编程
服务器
请选择您需要的素材分类 |
不限分类
每日更新
|
TOP排行榜
|
Tag标签
|
充值
无忧首页
网页模板
程序模板
建站教程
视频教程
网页特效
图标素材
字体下载
站长工具
站长问答
关闭顶部
展开顶部
网页特效
菜单导航
图片特效
文本链接
层和布局
页面背景
表单按钮
日期时间
计算转换
键盘鼠标
浏览器
游戏娱乐
综合其它
常用代码
jQuery特效
Prototype
Ajax/JavaScript
ExtJS
CSS特效
在线编辑器
Mootools
HTML
JS广告代码合集
站长工具
站长常用软件
网站综合查询
Alexa排名查询
Google PR查询
域名Whois查询
网站收录查询
友情链接查询
CSS2中文手册
CSS精简优化工具
AI小聚 能写会画
域名
推荐
展开边栏
关闭边栏
网页特效代码
模板无忧
>
网页特效
>
页面背景特效代码
>
收藏
分享
查看评论
页面背景
演示
Java Script 颜色梯度和渐变效果_页面背景特效
0/5
1
2
3
4
5
查看演示效果
特效Tag:
颜色
梯度
添加
织梦DedeCMS视频教程
买空间 租服务器 选网硕互联!
无忧站长工具,百度权重一键全查!
JavaScript 颜色梯度和渐变效果,您可以先修改部分代码再运行.
<!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" mrc="text/html; charset=gb2312" /> <title>JavaScript 颜色梯度和渐变效果</title> <script type="text/javascript"> var $ = function (id) { return "string" == typeof id ? document.getElementById(id) : id; }; var Extend = function(destination, source) { for (var property in source) { destination[property] = source[property]; } return destination; } var Map = function(array, callback, thisObject){ if(array.map){ return array.map(callback, thisObject); }else{ var res = []; for (var i = 0, len = array.length; i < len; i++) { res.push(callback.call(thisObject, array[i], i, array)); } return res; } } var ColorGrads = function(options){ this.SetOptions(options); this.StartColor = this.options.StartColor; this.EndColor = this.options.EndColor; this.Step = Math.abs(this.options.Step); }; ColorGrads.prototype = { //设置默认属性 SetOptions: function(options) { this.options = {//默认值 StartColor: "#fff",//开始颜色 EndColor: "#000",//结束颜色 Step: 20//渐变级数 }; Extend(this.options, options || {}); }, //获取渐变颜色集合 Create: function() { var colors = [], startColor = this.GetColor(this.StartColor), endColor = this.GetColor(this.EndColor), stepR = (endColor[0] - startColor[0]) / this.Step, stepG = (endColor[1] - startColor[1]) / this.Step, stepB = (endColor[2] - startColor[2]) / this.Step; //生成颜色集合 for(var i = 0, n = this.Step, r = startColor[0], g = startColor[1], b = startColor[2]; i < n; i++){ colors.push([r, g, b]); r += stepR; g += stepG; b += stepB; } colors.push(endColor); //修正颜色值 return Map(colors, function(x){ return Map(x, function(x){ return Math.min(Math.max(0, Math.floor(x)), 255); });}); }, //获取颜色数据 GetColor: function(color) { if(/^#[0-9a-f]{6}$/i.test(color)) {//#rrggbb return Map([color.substr(1, 2), color.substr(3, 2), color.substr(5, 2)], function(x){ return parseInt(x, 16); } ) } else if(/^#[0-9a-f]{3}$/i.test(color)) {//#rgb return Map([color.substr(1, 1), color.substr(2, 1), color.substr(3, 1)], function(x){ return parseInt(x + x, 16); } ) } else if(/^rgb(.*)$/i.test(color)) {//rgb(n,n,n) or rgb(n%,n%,n%) return Map(color.match(/\d+(\.\d+)?\%?/g), function(x){ return parseInt(x.indexOf("%") > 0 ? parseFloat(x, 10) * 2.55 : x, 10); } ) } else {//color var mapping = {"red":"#FF0000"};//略 color = mapping[color.toLowerCase()]; if(color){ return Map([color.substr(1, 2), color.substr(3, 2), color.substr(5, 2)], function(x){ return parseInt(x, 16); } ) } } } }; var CurrentStyle = function(element){ return element.currentStyle || document.defaultView.getComputedStyle(element, null); } var Bind = function(object, fun) { var args = Array.prototype.slice.call(arguments).slice(2); return function() { return fun.apply(object, args.concat(Array.prototype.slice.call(arguments))); } } //渐变对象 var ColorTrans = function(obj, options){ this._obj = $(obj); this._timer = null;//定时器 this._index = 0;//索引 this._colors = [];//颜色集合 this._grads = new ColorGrads(); this.SetOptions(options); this.Speed = Math.abs(this.options.Speed); this.CssColor = this.options.CssColor; this._startColor = this.options.StartColor || CurrentStyle(this._obj)[this.CssColor]; this._endColor = this.options.EndColor; this._step = Math.abs(this.options.Step); this.Reset(); this.SetColor(); }; ColorTrans.prototype = { //设置默认属性 SetOptions: function(options) { this.options = {//默认值 StartColor: "",//开始颜色 EndColor: "#000",//结束颜色 Step: 20,//渐变级数 Speed: 20,//渐变速度 CssColor: "color"//设置属性(Scripting属性) }; Extend(this.options, options || {}); }, //重设颜色集合 Reset: function(color) { //修改颜色后必须重新获取颜色集合 color = Extend({ StartColor: this._startColor, EndColor: this._endColor, Step: this._step }, color || {}); //设置属性 this._grads.StartColor = this._startColor = color.StartColor; this._grads.EndColor = this._endColor = color.EndColor; this._grads.Step = this._step = color.Step; //获取颜色集合 this._colors = this._grads.Create(); this._index = 0; }, //颜色渐入 FadeIn: function() { this.Stop(); this._index++; this.SetColor(); if(this._index < this._colors.length - 1){ this._timer = setTimeout(Bind(this, this.FadeIn), this.Speed); } }, //颜色渐出 FadeOut: function() { this.Stop(); this._index--; this.SetColor(); if(this._index > 0){ this._timer = setTimeout(Bind(this, this.FadeOut), this.Speed); } }, //颜色设置 SetColor: function() { var color = this._colors[Math.min(Math.max(0, this._index), this._colors.length - 1)]; this._obj.style[this.CssColor] = "rgb(" + color[0] + "," + color[1] + "," + color[2] + ")"; }, //停止 Stop: function() { clearTimeout(this._timer); } }; </script> </head> <body> <style type="text/css"> #idGrads{} #idGrads div{ font-size:0;height:1px;} </style> <div id="idGrads"> </div> <script> var forEach = function(array, callback, thisObject){ if(array.forEach){ array.forEach(callback, thisObject); }else{ for (var i = 0, len = array.length; i < len; i++) { callback.call(thisObject, array[i], i, array); } } } var colors = new ColorGrads({ StartColor: "#fff", EndColor: "rgb(20,127,0)" }).Create(); forEach(colors.concat().concat(colors.reverse()), function(x){ $("idGrads").innerHTML += "<div style=\"background-color:"+"rgb(" + x[0] + "," + x[1] + "," + x[2] + ");\"></div>"; }) </script> <Br /> <Br /> <style type="text/css"> #idMenu{ background:#DBDBDB;text-align:center;line-height:25px; table-layout:fixed;} #idMenu td{ cursor:pointer;} </style> <table id="idMenu" width="600" border="0" cellspacing="5" cellpadding="0"> <tr> <td onclick="location.href='http://www.cnblogs.com/cloudgamer/archive/2008/07/21/ImgCropper.html'">Cropper</td> <td onclick="location.href='http://www.cnblogs.com/cloudgamer/archive/2009/01/06/Tween.html'">Tween</td> <td onclick="location.href='http://www.cnblogs.com/cloudgamer/archive/2008/12/24/Slider.html'">Slider</td> <td onclick="location.href='http://www.cnblogs.com/cloudgamer/archive/2008/12/03/Resize.html'">Resize</td> <td onclick="location.href='http://www.cnblogs.com/cloudgamer/archive/2008/11/17/Drag.html'">Drag</td> </tr> </table> <script> forEach($("idMenu").getElementsByTagName("td"), function(x, i){ var ct1 = new ColorTrans(x, { StartColor: "#666", EndColor: "#fff" }); var ct2 = new ColorTrans(x, { StartColor: "#f6f6f6", EndColor: "rgb(20,150,0)", CssColor: "backgroundColor" }); x.onmouseover = function(){ ct1.FadeIn(); ct2.FadeIn(); } x.onmouseout = function(){ ct1.FadeOut(); ct2.FadeOut(); } }) </script> <Br /> <Br /> <div id="idRandom" style="padding:10px;color:#fff; background-color:#CCC;">点击随机换颜色</div> <script> var ctRandom = new ColorTrans("idRandom", { EndColor: "#CCC", CssColor: "backgroundColor" }) $("idRandom").onclick = function(){ var rgb = Map([1,1,1], function(){ return Math.floor((Math.random() * 255)); } ); ctRandom.Reset({ StartColor: this.style.backgroundColor, EndColor: "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")" }) ctRandom.FadeIn(); } </script> </body> </html>
所属频道:
页面背景特效
/
更新时间:2012-11-23
[收藏]
[报错]
[返回列表]
评论加载中....
相关
页面背景特效
:
推拉门式样的菜单(鼠标移上去即可,无需点击)
页面载入的动画效果的源代码一例
自动弹出的导航窗
页面载入时的进度条效果的实现
WEB对话框 可做网站登录协议用
左右幕布
在网页中添加上上下滚动的文字
弹出提示的效果
字符变色
一个很漂亮的转入别的页面时等待页
页面右下角弹类似QQ或MSN的消息提示
主题变色
页面背景特效Rss订阅
特效代码搜索
页面背景特效推荐
打开页面后跳出对话框,你可以用数字来指定链接目的地
可移动的显示层
左右幕布
runtimeStyle #079;bject
主题变色
CSS控制背景透明而内容不透明的方法
CSS渐变背景的6个演示代码
精美js鼠标跟随代码
弹出提示的效果
用选项卡控制DIV层切换改变背景颜色
猜你也喜欢看这些
纯CSS实现漂亮的分页按钮风格
JavaScript 点击单选按钮改变输入框(文本域)的内容
JS点击全选复选框
CSS给文本输入框添加背景图像
支持分类的Select下拉框(Optgroup标签示例)
变换链接色和底色
JS+CSS实现精致、符合标准的表单页面
一个不错的用CSS布局的表单
JS表单提交后按钮变灰代码
仿微软风格的按钮演示
相关链接:
复制本页链接
|
搜索Java Script 颜色梯度和渐变效果
特效说明:
页面背景模板
-
Java Script 颜色梯度和渐变效果
。
收藏&分享
QQ空间
新浪微博
腾讯微博
人人网
开心网
百度搜藏
复制网址
更多...