简介
实现类似于Photoshop控制面板输入文本数字的效果,所以名称叫做PsWheel。用于控制输入数字类型文本框实现鼠标滚轮上下滑动改变值,支持正整数、小数类型输入文本。
兼容IE/Firefox/Opera/Safari/Chrom
可定义滚动变化间隔值,支持整数、浮点数
双击恢复初始值
仅3.92K,压缩后2.67K
代码
复制代码 代码如下:
/*
* cutePsWheel JS
* Description:A js liabary which control the text type of input box can plus or minus value like Photoshop
* Author:walkingp
* Site:http://www.51obj.cn/
* E-mail:walkingp@126.com
* Last Modified:2010-2-5
*/
//Initial the wheel scroll event
var _orientValue=[];//orient value
var _interval=[];
var _length=[];
function InitScrollFunc(){
var eles=GetObj();
for(var i=0;i<eles.length;i++){
if(document.addEventListener){
(function(i){eles[i].addEventListener('DOMMouseScroll',function(e){e.preventDefault();e.stopPropagation();var direct=e.detail<0?1:-1;ScrollText(eles[i],direct);},false);})(i);
eles[i].addEventListener('dblclick',RestoreOrientValue,false);
eles[i].addEventListener('blur',RemoveScrollFunc,false);
//eles[i].addEventListener('mouseover',SetFocus,false);
}//W3C/Mozila
(function(i){eles[i].onmousewheel=function(){ScrollFunc(event,eles[i]);}})(i);//IE/Opera/Chrome/Safari
(function(i){eles[i].ondblclick=function(){RestoreOrientValue(eles[i]);;}})(i);
(function(i){eles[i].onblur=function(){RemoveScrollFunc(eles[i]);;}})(i);//Remove the wheel scroll event
(function(i){eles[i].onmouseover=function(){SetFocus(eles[i]);}})(i);
/*Initial the value array*/
if(eles[i].value!=""){
_orientValue.push(eles[i].value);
}else{
_orientValue.push(0);
}
if(eles[i].getAttribute("interval")){
_interval.push(parseFloat(eles[i].getAttribute("interval")));
if(eles[i].getAttribute("interval").toString().indexOf(".")>0){
var __length=parseInt(eles[i].getAttribute("interval").toString().length) - parseInt(eles[i].getAttribute("interval").toString().indexOf("."))-1;
_length.push(__length);//get the length follow the decimal point
}else{
_length.push(0);
}
}else{
_interval.push(1);
_length.push(0);
}
}
}
/*set object focus*/
function SetFocus(obj){
obj.focus();
obj.select();
}
/*remove the wheel scroll event*/
function RemoveScrollFunc(obj){
if(document.removeEventListener){
obj.removeEventListener('DOMMouseScroll',ScrollFunc,false);
obj.removeEventListener('dblclick',RestoreOrientValue,false);
}else if(document.detachEvent){
obj.detachEvent('onmousewheel',ScrollFunc);
obj.detachEvent('ondblclick',RestoreOrientValue);
}
}
/*Restore the text box's orient value when double click event trigger*/
function RestoreOrientValue(obj){
var eles=GetObj();
for(var i=0;i<eles.length;i++){
if(obj==eles[i]){
obj.value=_orientValue[i];
obj.select();
}
}
}
//core function
function ScrollFunc(){//for HTML DOM
var direct=0;
var e=arguments[0]||window.event;
if(window.event){
window.event.returnValue=false;
window.event.cancelBubble=true;//Stop event bubble
}
if(e.wheelDelta){
direct=e.wheelDelta>0?1:-1;
}
ScrollText(arguments[1],direct);
}
//reference by ScrollFunc
function ScrollText(obj,direct){
obj.focus();
var _value=0;
if(obj.value!=""){
_value=parseFloat(obj.value);
}
var eles=GetObj();
for(var i=0;i<eles.length;i++){
if(obj==eles[i]){
if(direct>0){
_value+=_interval[i];
}else{
_value-=_interval[i];
}
obj.value=_value.toFixed(_length[i]);//calulcate the rounding result
obj.select();//set select status
}
}
}
//referenced function,only get the object which has the 'rel' attribute
function GetObj(){
var objs=document.getElementsByTagName('input');
var elements=[];
for(var i=0;i<objs.length;i++){
if(objs[i].type=='text' && objs[i].getAttribute('rel') == 'wheel'){
elements.push(objs[i]);
}
}
return elements;
}
//Add the WheelScroll function
(function AddLoadEvent(func){
var _oldonload=window.onload;
if(typeof window.onload!='function'){
window.onload=func;
}else{
window.onload=function(){
_oldonload();
func();
}
}
})(InitScrollFunc);
效果图
资源
点击预览 http://demo.jb51.net/js/cutePSWheel/demo.html
下载代码
实现类似于Photoshop控制面板输入文本数字的效果,所以名称叫做PsWheel。用于控制输入数字类型文本框实现鼠标滚轮上下滑动改变值,支持正整数、小数类型输入文本。
兼容IE/Firefox/Opera/Safari/Chrom
可定义滚动变化间隔值,支持整数、浮点数
双击恢复初始值
仅3.92K,压缩后2.67K
代码
复制代码 代码如下:
/*
* cutePsWheel JS
* Description:A js liabary which control the text type of input box can plus or minus value like Photoshop
* Author:walkingp
* Site:http://www.51obj.cn/
* E-mail:walkingp@126.com
* Last Modified:2010-2-5
*/
//Initial the wheel scroll event
var _orientValue=[];//orient value
var _interval=[];
var _length=[];
function InitScrollFunc(){
var eles=GetObj();
for(var i=0;i<eles.length;i++){
if(document.addEventListener){
(function(i){eles[i].addEventListener('DOMMouseScroll',function(e){e.preventDefault();e.stopPropagation();var direct=e.detail<0?1:-1;ScrollText(eles[i],direct);},false);})(i);
eles[i].addEventListener('dblclick',RestoreOrientValue,false);
eles[i].addEventListener('blur',RemoveScrollFunc,false);
//eles[i].addEventListener('mouseover',SetFocus,false);
}//W3C/Mozila
(function(i){eles[i].onmousewheel=function(){ScrollFunc(event,eles[i]);}})(i);//IE/Opera/Chrome/Safari
(function(i){eles[i].ondblclick=function(){RestoreOrientValue(eles[i]);;}})(i);
(function(i){eles[i].onblur=function(){RemoveScrollFunc(eles[i]);;}})(i);//Remove the wheel scroll event
(function(i){eles[i].onmouseover=function(){SetFocus(eles[i]);}})(i);
/*Initial the value array*/
if(eles[i].value!=""){
_orientValue.push(eles[i].value);
}else{
_orientValue.push(0);
}
if(eles[i].getAttribute("interval")){
_interval.push(parseFloat(eles[i].getAttribute("interval")));
if(eles[i].getAttribute("interval").toString().indexOf(".")>0){
var __length=parseInt(eles[i].getAttribute("interval").toString().length) - parseInt(eles[i].getAttribute("interval").toString().indexOf("."))-1;
_length.push(__length);//get the length follow the decimal point
}else{
_length.push(0);
}
}else{
_interval.push(1);
_length.push(0);
}
}
}
/*set object focus*/
function SetFocus(obj){
obj.focus();
obj.select();
}
/*remove the wheel scroll event*/
function RemoveScrollFunc(obj){
if(document.removeEventListener){
obj.removeEventListener('DOMMouseScroll',ScrollFunc,false);
obj.removeEventListener('dblclick',RestoreOrientValue,false);
}else if(document.detachEvent){
obj.detachEvent('onmousewheel',ScrollFunc);
obj.detachEvent('ondblclick',RestoreOrientValue);
}
}
/*Restore the text box's orient value when double click event trigger*/
function RestoreOrientValue(obj){
var eles=GetObj();
for(var i=0;i<eles.length;i++){
if(obj==eles[i]){
obj.value=_orientValue[i];
obj.select();
}
}
}
//core function
function ScrollFunc(){//for HTML DOM
var direct=0;
var e=arguments[0]||window.event;
if(window.event){
window.event.returnValue=false;
window.event.cancelBubble=true;//Stop event bubble
}
if(e.wheelDelta){
direct=e.wheelDelta>0?1:-1;
}
ScrollText(arguments[1],direct);
}
//reference by ScrollFunc
function ScrollText(obj,direct){
obj.focus();
var _value=0;
if(obj.value!=""){
_value=parseFloat(obj.value);
}
var eles=GetObj();
for(var i=0;i<eles.length;i++){
if(obj==eles[i]){
if(direct>0){
_value+=_interval[i];
}else{
_value-=_interval[i];
}
obj.value=_value.toFixed(_length[i]);//calulcate the rounding result
obj.select();//set select status
}
}
}
//referenced function,only get the object which has the 'rel' attribute
function GetObj(){
var objs=document.getElementsByTagName('input');
var elements=[];
for(var i=0;i<objs.length;i++){
if(objs[i].type=='text' && objs[i].getAttribute('rel') == 'wheel'){
elements.push(objs[i]);
}
}
return elements;
}
//Add the WheelScroll function
(function AddLoadEvent(func){
var _oldonload=window.onload;
if(typeof window.onload!='function'){
window.onload=func;
}else{
window.onload=function(){
_oldonload();
func();
}
}
})(InitScrollFunc);
效果图
资源
点击预览 http://demo.jb51.net/js/cutePSWheel/demo.html
下载代码
标签:
CutePsWheel,滚轮控制
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“CutePsWheel javascript libary 控制输入文本框为可使用滚轮控制的js库”评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。