jquery插件--实现滑块控制颜色的效果
2012-03-29 21:54
513 查看
<!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" />
<title>jquery插件--实现滑块控制颜色的效果</title>
</head>
<style>
#red,#green,#blue{
float:left;
clear:left;
width:300px;
margin:15px;}
#swatch {
width: 120px;
height: 100px;
margin-top: 18px;
margin-left: 350px;
background-image: none;
}
#red .ui-slider-range { background: #ef2929; }
#red .ui-slider-handle { border-color: #ef2929; }
#green .ui-slider-range { background: #8ae234; }
#green .ui-slider-handle { border-color: #8ae234; }
#blue .ui-slider-range { background: #729fcf; }
#blue .ui-slider-handle { border-color: #729fcf; }
#demo-frame > div.demo { padding: 10px !important; };
</style>
<script language="javascript" type="text/javascript" src="./js/jquery-1.7.1.min.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery-ui-1.8.18.custom.min.js"></script>
<link type="text/css" href="./css/jquery-ui-1.8.18.custom.css" rel="stylesheet">
<script language="javascript" type="text/javascript">
function hexFromRGB(r,g,b){
var hex=[
r.toString(16),
g.toString(16),
b.toString(16)
];
$.each(hex,function (nr,val){
if ( val.length === 1 ) {
hex[ nr ] = "0" + val;
}
});
return hex.join( "" ).toUpperCase();
};
function refreshSwatch(){
var red=$("#red").slider("value");
var green=$("#green").slider("value");
var blue=$("#blue").slider("value");
hex = hexFromRGB( red, green, blue );
$( "#swatch" ).css( "background-color", "#" + hex );
};
$(document).ready(function(){
$("#red,#green,#blue").slider({
orientation:"horizontal",//滑块的方向 水平
range:"min",
max:255,//滑块的最大值
value:127,//最大值-最小值
slide:refreshSwatch,
change:refreshSwatch,
});
$( "#red" ).slider( "value", 255 );
$( "#green" ).slider( "value", 140 );
$( "#blue" ).slider( "value", 60 );
});
</script>
<body class="ui-widget-content" style="border:0;">
<div id="demo">
<p class="ui-state-default ui-corner-all ui-helper-clearfix" style="padding:4px;">
<span class="ui-icon ui-icon-pencil" style="float:left; margin:-2px 5px 0 0;"></span>
Simple Colorpicker
</p>
<div id="red"></div>
<div id="green"></div>
<div id="blue"></div>
<div id="swatch" class="ui-widget-content ui-corner-all"></div>
</div>
<div class="demo-description" style="clear:left;">
<p>Combine three sliders to create a simple RGB colorpicker.</p>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery插件--实现滑块控制颜色的效果</title>
</head>
<style>
#red,#green,#blue{
float:left;
clear:left;
width:300px;
margin:15px;}
#swatch {
width: 120px;
height: 100px;
margin-top: 18px;
margin-left: 350px;
background-image: none;
}
#red .ui-slider-range { background: #ef2929; }
#red .ui-slider-handle { border-color: #ef2929; }
#green .ui-slider-range { background: #8ae234; }
#green .ui-slider-handle { border-color: #8ae234; }
#blue .ui-slider-range { background: #729fcf; }
#blue .ui-slider-handle { border-color: #729fcf; }
#demo-frame > div.demo { padding: 10px !important; };
</style>
<script language="javascript" type="text/javascript" src="./js/jquery-1.7.1.min.js"></script>
<script language="javascript" type="text/javascript" src="./js/jquery-ui-1.8.18.custom.min.js"></script>
<link type="text/css" href="./css/jquery-ui-1.8.18.custom.css" rel="stylesheet">
<script language="javascript" type="text/javascript">
function hexFromRGB(r,g,b){
var hex=[
r.toString(16),
g.toString(16),
b.toString(16)
];
$.each(hex,function (nr,val){
if ( val.length === 1 ) {
hex[ nr ] = "0" + val;
}
});
return hex.join( "" ).toUpperCase();
};
function refreshSwatch(){
var red=$("#red").slider("value");
var green=$("#green").slider("value");
var blue=$("#blue").slider("value");
hex = hexFromRGB( red, green, blue );
$( "#swatch" ).css( "background-color", "#" + hex );
};
$(document).ready(function(){
$("#red,#green,#blue").slider({
orientation:"horizontal",//滑块的方向 水平
range:"min",
max:255,//滑块的最大值
value:127,//最大值-最小值
slide:refreshSwatch,
change:refreshSwatch,
});
$( "#red" ).slider( "value", 255 );
$( "#green" ).slider( "value", 140 );
$( "#blue" ).slider( "value", 60 );
});
</script>
<body class="ui-widget-content" style="border:0;">
<div id="demo">
<p class="ui-state-default ui-corner-all ui-helper-clearfix" style="padding:4px;">
<span class="ui-icon ui-icon-pencil" style="float:left; margin:-2px 5px 0 0;"></span>
Simple Colorpicker
</p>
<div id="red"></div>
<div id="green"></div>
<div id="blue"></div>
<div id="swatch" class="ui-widget-content ui-corner-all"></div>
</div>
<div class="demo-description" style="clear:left;">
<p>Combine three sliders to create a simple RGB colorpicker.</p>
</div>
</body>
</html>
相关文章推荐
- jquery插件滑块效果的实现
- 用jquery插件-slider实现滑块的效果
- 利用jquery-fform.js插件实现图片所见即所得效果
- ASP.NET中使用jQuery插件实现图片幻灯效果
- Jquery左右滑动插件之实现超级炫酷动画效果附源码下载
- 采用Jquery无刷新分页插件jquery.pagination.js 实现无刷新分页效果
- 插件在线BookBlock:一个实现翻页效果的jQuery插件
- jquery自定义插件来实现分页的效果
- 利用jQuery和JS实现奇偶行背景颜色自定义效果
- jQuery animate()实现背景色渐变效果的处理方法【使用jQuery.color.js插件】
- jQuery圆角插件,实现兼容浏览器圆角效果
- jQuery插件实现的页面功能介绍引导页效果
- jQuery实现Div拖动+键盘控制综合效果的方法
- Jquery实现弹出层分享微博插件具备动画效果
- 使用HTML5和jQuery插件Reel实现一个超酷的星际争霸2兵种动画360度预览效果
- ****timeago.js插件:jquery实现几分钟前、几小时前、几天前等时间差显示效果的代码实例
- Jquery实现弹性滑块滑动选择数值插件
- 推荐六款帮助你实现惊艳视差滚动效果的 jQuery 插件
- JQuery插件实现相册效果(数据库调用图片)