/**
*进度条
*/
var ProgressScrollBar = function (model) {
this.defaults = {
isCanMove: true,//是否启用拖动
container: "",//最外容器ID
Mainselector: "", //主要div的ID jq选择器字符串#id
Textselector: false, //文字显示查找选择器inputobj
value: 0, //初始值
maxValue: 200, //最大值
currentX: 0,//当前位置px单位
scroll_Track: false, //主干线对象
scroll_Thumb: false //图标对象

};
var opt = $.extend(this.defaults, model);
var mainDivWidth = 0;
var mSelector;
var $Textselector;
var offetWidth;
//初始化
this.Initialize = function () {
if (opt.value > opt.maxValue) {
alert("给定当前值大于了最大值");
return;
}
mSelector = $(opt.Mainselector);
$Textselector = opt.Textselector;
if (!opt.scroll_Track) {
mSelector.append('<div class="scroll_Track"></div>');
opt.scroll_Track = mSelector.find(".scroll_Track");
}
if (!opt.scroll_Thumb) {
mSelector.append('<div class="scroll_Thumb"></div>');
opt.scroll_Thumb = mSelector.find(".scroll_Thumb");
}
mainDivWidth = mSelector.width(); //当前idv宽度
offetWidth = opt.scroll_Thumb.width();

this.GetValue();
opt.scroll_Track.css("width", opt.currentX + 2 + "px");
opt.scroll_Thumb.css("margin-left", opt.currentX + "px");
if (opt.isCanMove) {
this.Value();
}
if ($Textselector && opt.value >= 0)
$Textselector.val(opt.value);
},
this.Value = function () {
var valite = false;
var currentValue;
opt.scroll_Thumb.mousedown(function () {
valite = true;
mSelector.parent().mousemove(function (event) {
console.log(event.offsetX + ", cleint:" + event.clientX + ", parent: " + mSelector.parent().offset().left);

if (valite == false) return;
var changeX = event.clientX - opt.currentX;
currentValue = changeX - opt.currentX - mSelector.offset().left - (offetWidth / 2);
opt.scroll_Thumb.css("margin-left", currentValue + "px");
opt.scroll_Track.css("width", currentValue + 2 + "px");
if ((currentValue + offetWidth) >= mainDivWidth) {
opt.scroll_Thumb.css("margin-left", mainDivWidth - offetWidth + "px");
opt.scroll_Track.css("width", mainDivWidth + 2 + "px");
opt.value = opt.maxValue;
} else if (currentValue <= 0) {
opt.scroll_Thumb.css("margin-left", "0px");
opt.scroll_Track.css("width", "0px");
} else {
opt.value = parseInt(opt.maxValue * (currentValue / mainDivWidth));
}
if ($Textselector && opt.value >= 0)
$Textselector.val(opt.value);
});
});
opt.scroll_Thumb.mouseup(function () {
opt.value = parseInt(opt.maxValue * (currentValue / mainDivWidth));
valite = false;
if (opt.value >= opt.maxValue) opt.value = opt.maxValue;
if (opt.value <= 0) opt.value = 0;
if ($Textselector && opt.value >= 0)
$Textselector.val(opt.value);
});

},
this.GetValue = function () {
opt.currentX = mainDivWidth * (opt.value / opt.maxValue);
},
//按值自动滚动
this.SetValue = function (aValue) {
opt.value = aValue;
if (opt.value >= opt.maxValue) opt.value = opt.maxValue;
if (opt.value <= 0) opt.value = 0;
var mWidth = opt.value / opt.maxValue * mainDivWidth;
opt.scroll_Thumb.animate({ "margin-left": mWidth + "px" });
opt.scroll_Track.animate({ "width": mWidth + 2 + "px" });
if ((mWidth + offetWidth) >= mainDivWidth) {
opt.scroll_Thumb.animate({ "margin-left": mainDivWidth - offetWidth + "px" });
opt.scroll_Track.animate({ "width": mainDivWidth + 2 + "px" });
} else if (mWidth <= 0) {
opt.scroll_Thumb.animate({ "margin-left": "0px" });
opt.scroll_Track.animate({ "width": "0px" });
} else {
opt.value = Math.round(opt.maxValue * (mWidth / mainDivWidth));
}
if ($Textselector && opt.value >= 0)
$Textselector.val(opt.value);
},
//按像素自动滚动
this.SetPixelValue = function (pixelValue) {
opt.scroll_Thumb.animate({ "margin-left": pixelValue + "px" });
opt.scroll_Track.animate({ "width": pixelValue + "px" });
if ((pixelValue + offetWidth) >= mainDivWidth) {
opt.scroll_Thumb.animate({ "margin-left": mainDivWidth - offetWidth + "px" });
opt.scroll_Track.animate({ "width": mainDivWidth + "px" });
} else if (pixelValue <= 0) {
opt.scroll_Thumb.animate({ "margin-left": "0px" });
opt.scroll_Track.animate({ "width": "0px" });
} else {
opt.value = Math.round(opt.maxValue * (pixelValue / mainDivWidth));
}
}
}

jq 进度条插件的更多相关文章

  1. YprogressBar,html5进度条样式,js进度条插件

    简介 YprogressBar是一款基于HTML5的进度条插件. YprogressBar是一款轻量级进度条插件,使用方便,资源占用少,模仿好压的解压界面,带有数字显示,同时支持在描述中增加参数,以动 ...

  2. 简单实用的纯CSS百分比圆形进度条插件

    percircle是一款简单实用的纯CSS百分比圆形进度条插件.你不需要做任何设置,只需要按该圆形进度条插件提供的标准HTML结构来编写代码,就可以生成一个漂亮的百分比圆形进度条. 首先要做的就是引入 ...

  3. 一个Notification 进度条插件(android,NJS实现,直接就可使用)

    参考文章:http://ask.dcloud.net.cn/article/503 源码地址下载 如题,分享一个Notification 进度条插件(android,用js调用原生api实现,直接就可 ...

  4. 30款基于 jQuery & CSS3 的加载动画和进度条插件

    我们所生活每一天看到的新技术或新设计潮流的兴起,Web 开发正处在上升的时代.HTML5 & CSS3 技术的发展让 Web 端可以实现的功能越来越强大. 加载动画和进度条使网站更具吸引力.该 ...

  5. JQuery中简约的进度条插件推荐

    JQuery Progress Bar是基于JQuery开发的进度条插件,秉承了JQuery的简约哲学.不仅容易使用,而且可以轻松定制外观.对于使用了JQuery框架的项目来说,需要使用进度条控件时这 ...

  6. 基于Jquery的进度条插件(实用)

    Spin.js 最喜欢这款插件了,动画图片的长度.粗细.速度和角度都可以灵活控制,想要做成什么样都可以. 源码下载    在线演示   Percentage Loader 一款轻量的 jQuery 进 ...

  7. 简单的jquery进度条插件LineProgressbar.js,myProgress.js

    参考   http://www.lanrenzhijia.com/jquery/4121.html demo下载 <script src="js/jquery.lineProgress ...

  8. HTML5圆形百分比进度条插件circleChart

    在页面中引入jquery和circleChart.min.js文件. <script src="path/to/jquery.min.js"></script&g ...

  9. ajax页面加载进度条插件

    下面两个都是youtube视频的加载进度条效果的ajax插件 一.官网:http://ricostacruz.com/nprogress/官网 github:https://github.com/rs ...

随机推荐

  1. HTML5扩展之微数据与丰富网页摘要itemscope, itemtype, itemprop

    HTML5扩展之微数据与丰富网页摘要 by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpr ...

  2. Python基础知识学习_Day1

    1,python介绍 诞生于1989年圣诞节,目前越来越受到业界认可.应用领域十分广泛 云计算: 云计算最火的语言, 典型应用OpenStack WEB开发: 众多优秀的WEB框架,众多大型网站均为P ...

  3. js便利关联数组 及数组定义方式 分类

    "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv=& ...

  4. 导入libxml.dylib用Google的GDataXML解析XML数据

    1.用Google的GDataXML来解析XML数据,导入libxml.dylib 2.导入libxml.dylib的操作实现,一开始自己总是找不到libxml.dylib文件. 选择其他文件,到路径 ...

  5. WCF发布错误及解决方案

    一:在本机直接运行时出错 使用WCF写了一个小程序测试一下它的功能在运行时报错.“添加服务失败.服务元数据可能无法访问.请确保服务正在运行并且正在公开元数据.” 如下图所示: 查了下资料把它解决了,记 ...

  6. C++实现中缀表达式转前、后缀

    #include<iostream> #include<string> #include<stack> using namespace std; bool isIn ...

  7. CSS 选择器之基本选择器 属性选择器 伪类选择器

    CSS 选择器 常见的选择器列表图 CSS选择器笔记 基本选择器 通配符选择器(*) 元素选择器(E) 类选择器(.className)    所有浏览器都支持类选择器,但多类选择器(.classNa ...

  8. 雄冠条码PV系统-2016-05-17-收获

    Q1:微信浏览器 input获取焦点时,页面宽度变大 解决方法: HTML <header> 中添加<meta name="viewport" content=& ...

  9. iOS身份证号码识别

    一.前言   身份证识别,又称OCR技术.OCR技术是光学字符识别的缩写,是通过扫描等光学输入方式将各种票据.报刊.书籍.文稿及其它印刷品的文字转化为图像信息,再利用文字识别技术将图像信息转化为可以使 ...

  10. javascript location对象

    location用于获取或设置窗体的URL,并且可以用于解析URL. location.[属性|方法] 1.location对象属性图示: 2.location 对象属性: 3.location 对象 ...