为什么80%的码农都做不了架构师?>>>   

jQuery刻度尺滚动滑块插件

需要用到一个刻度尺插件,网上找来找去都是那几种,所以用jQuery自己写了一个。

<!doctype html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

<link href="css/mui.min.css" rel="stylesheet" />

<style>

.mui-content { background: #e8e8e8;}

#main {

position: relative;

margin-left: 50%;

margin-top: 100px;

width: 2560px;

font-family: 微软雅黑;

-webkit-user-select: none;

background: #e8e8e8;

height: 100px;

}

#contain {

position: absolute;

top: 0px;

right: 0px;

width: 2560px;

height: 50px;

background-color: #fff;

/*配置marginRight=560px-1px,血糖值为7.0*/

margin-right: 559px;

}

#track {

position: absolute;

top: 0px;

left: 0px;

width: 2px;

height: 56px;

margin: -3px 0 0 0px;

background-color: red/*#2dacd1*/;

cursor: pointer;

}

#value>span {

position: absolute;

text-align: right;

height: 40px;

line-height: 80px;

color: #808080;

border-right: 1px solid #ddd;

}

#value>span span {

position: absolute;

height: 30px;

border-right: 1px solid #ddd;

}

#show {

width: 45px;

height: 30px;

background-color: #333;

color: #fff;

text-align: center;

line-height: 30px;

position: absolute;

left: 0px;

top: 0px;

opacity: 0.9;

margin-top: -38px;

margin-left: -20px;

}

.f14 { font-size: 14px;}

.c5, a.c5 { color: #666;}

</style>

</head>

<body>

<header class="mui-bar mui-bar-nav">

<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left c5"></a>

<h1 class="mui-title mui-text-left c5">手动记录</h1>

</header>

<div class="mui-content">

<div class="mui-content-padded f14 c5">

<span></span>血糖导入<span class="mui-icon mui-icon-arrowright mui-pull-right"></span><span class="mui-pull-right">掌糖设备</span>

</div>

<div id="main">

<div id="contain">

<div id="value"></div>

</div>

<div id="show">7.0</div>

<div id="track"></div>

</div>

</div>

<script src="js/mui.min.js"></script>

<script src="js/jquery-1.11.0.js"></script>

<script type="text/javascript">

$(function(){ScrollerTrack.Init();});

var ScrollerTrack={

BodyWidth: 2560,//总宽度

MaxValue: 32.0,//厘米最大值

CurrentX: 0,//移动距离

CurrentValue: 0,//移动的刻度数

Count: 0,//厘米刻度数量

SCALE: 10,//一厘米有多少毫米刻度

Init:function(){

var mWidth=ScrollerTrack.BodyWidth;//刻度计总的宽度

$("#contain").css("width",mWidth+"px");//主容器宽度

//厘米刻度数量=最大值除以1

var count=ScrollerTrack.MaxValue/1;

//赋值厘米刻度数量

ScrollerTrack.Count=count;

//一个厘米的宽度=总宽度除以厘米数量

var itemWidth=mWidth/count;

//一厘米有多少个毫米

var scale = ScrollerTrack.SCALE;

//毫米宽度=一厘米宽度除以10

var dialsWidth = itemWidth/10;

//循环渲染页面,显示刻度

for(var i=0;i<count;i++){

var span=$("<span>"+(i+1)+".0"+"</span>");

$(span).css("width",itemWidth+"px").css("margin-left",i*itemWidth+"px").css("color","#55bfc5");

$("#value").append(span);

for(var r=0;r<scale;r++){

var dials=$("<span></span>");

$(dials).css("width",dialsWidth+"px").css("margin-left",r*dialsWidth+"px").css("left","0px");

$(span).append(dials);

}

}

ScrollerTrack.Value();

},

//取值

Value: function(){

var currentValue;

var isMoving=false;

$("#contain").mousedown(function(e) {

//点击屏幕时刻度尺的右margin值

var val = parseInt($("#contain").css('marginRight'));

var target=$(this).parent();

//拖动开始时的x坐标

var downX = e.clientX;

isMoving=true;

$("html,body").mousemove(function(event) {

ScrollerTrack.CurrentX = val;

if(isMoving==false)return;

//移动的x轴距离=拖动开始的X坐标-拖动结束的X坐标,正数是左滑动,负数是右滑动

var changeX = downX - event.clientX;

//左滑动

if(changeX >= 0){

ScrollerTrack.CurrentX += changeX;

//右滑动取正数

}else{

//取正数

changeX = -changeX;

ScrollerTrack.CurrentX -= changeX;

}

if(ScrollerTrack.CurrentX<=0){

$(target).find("#contain").css("margin-right", "0px");

$(target).find("#show").html(0);

$("#numbox").html(0);

ScrollerTrack.CurrentValue=0;

ScrollerTrack.CurrentX = 0;

}

else if(ScrollerTrack.CurrentX>= ScrollerTrack.BodyWidth-1){

$(target).find("#contain").css("margin-right", ScrollerTrack.BodyWidth-1 + "px");

$(target).find("#show").html(ScrollerTrack.MaxValue);

$('#numbox').html(ScrollerTrack.MaxValue);

ScrollerTrack.CurrentValue=ScrollerTrack.MaxValue;

ScrollerTrack.CurrentX = ScrollerTrack.MaxValue;

}

else{

$(target).find("#contain").css("margin-right", ScrollerTrack.CurrentX +"px");

var v=ScrollerTrack.MaxValue*(ScrollerTrack.CurrentX/ScrollerTrack.BodyWidth);

$(target).find("#show").html(parseFloat(v).toFixed(1));

$('#numbox').html(parseFloat(v).toFixed(1));

ScrollerTrack.CurrentValue=parseFloat(v).toFixed(1);

}

});

});

$("html,body").mouseup(function() {

isMoving=false;

});

}

}

</script>

</body>

</html>

转载于:https://my.oschina.net/af666/blog/813617

jQuery刻度尺滚动滑块插件相关推荐

  1. js原生刻度尺滚动滑块插件

    为什么80%的码农都做不了架构师?>>>    js原生刻度尺滚动滑块插件 用的MUI框架,原生兼容性很好,性能也更好,所以费了很大的力气改成原生的分享给大家. 有时间了改成手机版. ...

  2. html 文件域变滑块,小巧的jQuery区域范围滑块插件noUiSlider

    小巧的jQuery区域范围滑块插件noUiSlider 分类:代码 日期:2020-02-10 点击(21,970) 下载(0) 来源:未知 收藏 区域范围滑块在 Windows 系统中很常见,如更改 ...

  3. 【特别推荐】精心挑选的6款优秀的 jQuery 视差滚动效果插件

    视差(Parallax)是指从不同的点看一个物体时形成的视觉差异,这个名词是源自希腊文的παράλλαξις (parallaxis),意思是"改变".在网页设计中,视差滚动(Pa ...

  4. 15个非常棒的jQuery无限滚动插件【瀑布流效果】

    现在,最热门的网站分页趋势之一是jQuery的无限滚动(也即瀑布流).如果你碰巧观察Pinterest的网站,如Facebook,Twitter和deviantART的,你会发现无限滚动的动作,当旧的 ...

  5. 前端开发不容错过的jQuery图片滑块插件(转)

    作为前端开发者,我们会碰到很到各种各样的jQuery插件.今天要分享的几款jQuery图片滑块插件,也就是jQuery焦点图插件,基本上会在每个网站都有应用,可以下载看看,也许你可以用到. 1.jQu ...

  6. jquery 图像滑块_10个很棒的jQuery图像滑块插件

    jquery 图像滑块 The introduction of jQuery has contributed a lot in making the overall process of websit ...

  7. [置顶]       Web开发百宝箱——提升网站档次的时尚 jQuery 图片滚动插件

    这篇文章向大家推荐8款时尚的 jQuery 图片滚动插件.jQuery 是最流行和使用最广泛的 JavaScript 框架,它可以让帮助你在你的项目中加入一些很炫的图片滚动效果.希望这些插件对你有所帮 ...

  8. Flexslider - 响应式的 jQuery 内容滚动插件

    FlexSlider 是一款轻量的响应式 jQuery 内容滚动插件,能够帮助你在项目轻松的创建漂亮的内容滚动效果.这款插件曾经连续多年入选 WDL 的年度最佳 jQuery 插件,值得大家在网站开发 ...

  9. php抽奖的数字滚动器,jQuery数字滚动插件

    [温馨提示]源码包解压密码:www.youhutong.com 效果图: 描述说明: jQuery数字滚动效果,可调整不同位数 使用方法 导入index.js html js调用$("#da ...

最新文章

  1. Node.js开发环境的搭建
  2. EXTJS 常用控件的使用
  3. Node Opencv Addon
  4. (学习日记)关于a1,a2,a3,...,an共n个元素依次入栈其可能出栈的排列数的计算(catalan数)...
  5. subline text 快捷键
  6. move std 函数 示例_C++ STL迭代器辅助函数
  7. 谈谈我这几年的C++学习之路
  8. ArcGIS工具之ET GeoWizards、GeoTools、GeoTools
  9. NandFlash启动理解(S3C2410)
  10. 森林图怎么分析_新疆森林消防总队特勤大队:“火焰蓝”备战春防,我们时刻准备着!...
  11. ormlite的使用方法
  12. Swift3.0服务端开发(二) 静态文件添加、路由配置以及表单提交
  13. Linux学习初识redhat7(一)
  14. 论文写作——小白如何写好并投稿自己的第一篇英文论文?
  15. 常有不规则动词的过去式和过去分词…
  16. php 输入经纬度查询位置,PHP根据一个给定经纬度的点,进行附近地点查询
  17. 程序员需要学会宏观看待问题
  18. Java数据类型和方法练习题
  19. Windows10关于拨号上网热点分享的操作
  20. 台前与幕后的5G战争

热门文章

  1. 如何点击打印,直接打印出来,不弹打印设置选项
  2. python中如何将字典直接变成二维数组_python基础知识(列表、字典、二维数组)...
  3. process 类 java_编写可执行jar——java的Process类的使用(二)
  4. matlab画无量纲速度分布,麦克斯韦分布与概率论中典型分布的比较教学
  5. oracle outln用户,Oracle用户解锁
  6. angular js 默认选中_AngularJS Select(选择框)
  7. gettype获取类名_在TypeScript中运行时获取对象的类名
  8. Multi GET API介绍
  9. 前后端分离,如何解决跨域问题
  10. 互联网晚报 | 2月28日 星期一 |​工信部:最大限度降低缺芯影响;​工信部:今年新建5G基建60万个...