Never Sliderbar (JS version of the simple Sliding bar control)

Source: Internet
Author: User
js| Control

Web slider, Web scroll bar, JS scroll bar, sliding bar control, JS Sliderbar

has been updated again:
Support real-time monitoring of sliderbar data, allow callback callback functions, examples, continuous updates ...

1, can be customized style setstyle ()
2, with Onsroll function
3, have setsldpoint (set position) interface
4, has the Getsldpoint (obtains the position) the interface
5, can set the maximum value of Sliderbar (not sliderbar length, but value)
6, custom fine-tuning function (Setincrement (10)), the default is 5; <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> never Slider Bar </TITLE>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "Never-online, Bluedestiny" >
<meta name= "Keywords" content= "JavaScript Slider Bar" >
<meta name= "Description" content= "JavaScript Slider Bar" >
<style>
Body {background-color: #fff; text-align:center; font-family:verdana; font-size:9pt;}
. sliderobj {width:350px; height:25px background-color: #fff; border:1px solid #666666;}
. sliderbar {width:20px; Background-color: #666666; border:1px solid #333;}
. sliderbtn {width:30px background-color: #666666; color: #fff; border:1px solid #000000;}
. r-sliderobj {width:300px; height:25px background-color: #fff; border:1px solid #CC0000;}
. r-sliderbar {width:20px; Background-color: #CC0000; border:1px solid #333;}
. r-sliderbtn {width:20px background-color: #CC0000; color: #fff; border:1px solid #000000;}
. g-sliderobj {width:300px; height:25px background-color: #fff; border:1px solid #006600;}
. g-sliderbar {width:20px; Background-color: #006600; border:1px solid #333;}
. g-sliderbtn {width:20px background-color: #006600; color: #fff; border:1px solid #000000;}
. b-sliderobj {width:300px; height:25px background-color: #fff; border:1px solid #003399;}
. b-sliderbar {width:20px; Background-color: #003399; border:1px solid #333;}
. b-sliderbtn {width:20px background-color: #003399; color: #fff; border:1px solid #000000;}
</style>
</HEAD>
<BODY>
<p>
<div id= "S1" ></div>
<p>
<div id= "D1" >r</div>
<p>
<div id= "S2" ></div>
<p>
<div id= "D2" >g</div>
<p>
<div id= "S3" ></div>
<p>
<div id= "D3" >b</div>
<p>
<div id= "Color" class= "Sliderobj" ></div>
<script language= "JavaScript" >
<!--
/*===============================================================
//
Module:never Sliderbar
Script By:never-online, Bluedestiny
Updated:2006-5-12
Copyright:miracle technology all reserved
Website:http://www.never-online.net
Email:bluedestiny@126.com
Blog:http://blog.csdn.net/bluedestiny
Comment:if you using the never Sliderbar please hold
These copyrights.
//
Compatible:only for IE
History:none
//
================================================================*/

function Neversliderbar (id,callback) {with (this) {
this.$ = document.getElementById | | document.all;
This.sldid = ID;
This.sldobj = null;
This.instance = this;
This.barstyle = "Sliderbar";
This.objstyle = "Sliderobj";
This.btnstyle = "SLIDERBTN";
This.sldbar = null;
THIS.SLDBTNL = null;
THIS.SLDBTNR = null;
This.sldpoint = null;
This.sldmoved = false;
this.sldclicked = false;
This.callback = callback;
This.sldobjoffset = null;
This.sldbaroffset = null;
This.callbackarg = Array.prototype.slice.call (arguments,2);
This.sldmax = 100;
This.sldincrement = 5;
This.sldpoint = 0;
Instance.init.call (This,id);
}};
Neversliderbar.prototype.setobjstyle=function (classname) {with (this)
{
Objstyle=classname;
}};
Neversliderbar.prototype.setmaxpoint=function (MaxPoint) {with (this)
{
Sldmax=maxpoint;
}};
Neversliderbar.prototype.setbtnstyle=function (classname) {with (this)
{
Btnstyle=classname;
}};
Neversliderbar.prototype.setbarstyle=function (classname) {with (this)
{
Barstyle=classname;
}};
Neversliderbar.prototype.setstyle=function () {with (this)
{
if (Arguments[0]) barstyle=arguments[0];
if (Arguments[1]) btnstyle=arguments[1];
if (arguments[2]) objstyle=arguments[2];
}};
Neversliderbar.prototype.setincrement=function (increment) {with (this)
{
if (isNaN (parseint (increment)) return;
Sldincrement = parseint (increment);
}};
Neversliderbar.prototype.getsldpoint=function () {with (this)
{
Sldbaroffset = Offset (Sldbar);
Sldobjoffset = Offset (sldobj);
var sldobjwidth = SLDOBJOFFSET.W-SLDBAROFFSET.W;
var sldbarwidth = SLDBAROFFSET.L-SLDOBJOFFSET.L;
var sldlocation = parseint (Sldbarwidth/sldobjwidth*sldmax);
return sldlocation;
}};
Neversliderbar.prototype.setsldpoint=function (point) {with (this)
{
if (isNaN (parseint)) return;
if (point<0) point=0;
if (Point>sldmax) Point=sldmax;
var sldobjwidth = SLDOBJOFFSET.W-SLDBAROFFSET.W;
var sldbarwidth = SLDBAROFFSET.L-SLDOBJOFFSET.L;
Sldpoint = parseint (point);
var p = parseint (Sldpoint*sldobjwidth/sldmax) +sldobjoffset.l+1;
SldBar.style.left = p;
Instance.getsldpoint ();
}};

Neversliderbar.prototype.init=function () {with (this)
{
if ($ (sldid + ' __BTNL ') && $ (sldid + ' __btnr ') && $ (sldid + ' __bar ')) {
SLDBTNL = $ (sldid + ' __btnl ');
Sldbar = $ (sldid + ' __bar ');
SLDBTNR = $ (sldid + ' __btnr ');
}
else {
SLDBTNL = document.createelement ("button");
Sldbtnl.id = Sldid + ' __BTNL ';
Sldbar = document.createelement ("DIV");
Sldbar.id = Sldid + ' __bar ';
Sldbtnr = document.createelement ("button");
Sldbtnr.id = Sldid + ' __btnr ';
Document.body.appendChild (SLDBTNL);
Document.body.appendChild (Sldbar);
Document.body.appendChild (SLDBTNR);
}
//-------------------------------------------------------------------
Sldobj = $ (sldid);
Sldobj.classname = Objstyle;
Sldbaroffset = Offset (Sldbar);
Sldobjoffset = Offset (sldobj);
//-------------------------------------------------------------------
Sldbtnl.value = "<<";
Sldbtnl.classname = Btnstyle;
SldBtnL.style.position = "absolute";
//-------------------------------------------------------------------
Sldbtnr.value = ">";
Sldbtnr.classname = Btnstyle;
SldBtnR.style.position = "absolute";
//-------------------------------------------------------------------
Sldbar.classname = Barstyle;
SldBar.style.position = "absolute";
SldBar.style.top = sldobjoffset.t;
SldBar.style.height = sldObjOffset.h;
SldBar.style.left = SLDOBJOFFSET.L;
Instance.fixed ();
//-------------------------------------------------------------------
Sldobj.onmousedown = function () {Instance.handleobjbefore ()};
Sldobj.onmouseup = function () {instance.handleobjafter ()};
//-------------------------------------------------------------------
Sldbtnl.onmousedown = function () {Instance.handlebtnclick (' l ')};
Sldbtnr.onmousedown = function () {Instance.handlebtnclick (' R ')};
Sldbtnl.onfocus = function () {This.blur ()};
Sldbtnr.onfocus = function () {This.blur ()};
//-------------------------------------------------------------------
Sldbar.onmousedown = function () {Instance.handleslddragstart ()};
Sldbar.onmousemove = function () {Instance.handleslddrag ()};
Sldbar.onmouseup = function () {instance.handleslddragend ()};
}};
Neversliderbar.prototype.fixed=function () {with (this)
{
Sldbaroffset = Offset (Sldbar);
Sldobjoffset = Offset (sldobj);

var sldbtnloffset = Offset (SLDBTNL);
SldBtnL.style.left = SLDOBJOFFSET.L-SLDBTNLOFFSET.W;
SldBtnL.style.top = sldobjoffset.t;
SldBtnL.style.height = sldObjOffset.h;
//-------------------------------------------------------------------
SldBtnR.style.left = SLDOBJOFFSET.L+SLDOBJOFFSET.W;
SldBtnR.style.top = sldobjoffset.t;
SldBtnR.style.height = sldObjOffset.h;
//-------------------------------------------------------------------
SldBar.style.top = sldobjoffset.t;
SldBar.style.height = sldObjOffset.h;
//-------------------------------------------------------------------
var p = sldbaroffset.l;
if (P < sldobjoffset.l) sldbar.style.left=sldobjoffset.l;
var w = SLDOBJOFFSET.L+SLDOBJOFFSET.W-SLDBAROFFSET.W;
if (P > W) sldBar.style.left = w;
Window.settimeout (function () {instance.fixed ()},10)
}};
Neversliderbar.prototype.applyarg=function () {with (this)
{
if (typeof (callback) = = ' string ') Callback=eval (callback);
if (typeof (callback) = = ' function ') {
var callbackarguments = [];
for (var i=0; i<callbackarg.length; i++)
Callbackarguments[i] = Callbackarg[i];
Callbackarguments.push (Instance.getsldpoint ());
Callback.apply (this,callbackarguments);
else {return;}
}};
Neversliderbar.prototype.handleobjbefore=function () {with (this)
{

}};
Neversliderbar.prototype.handleobjafter=function () {with (this)
{

}};
Neversliderbar.prototype.handlebtnclick=function (direction) {with (this)
{
Direction = Direction.tolowercase ();
Sldpoint=instance.getsldpoint ();
if (direction = = ' L ') {
Instance.setsldpoint (this.sldpoint-sldincrement);
}
else if (direction== ' R ') {
Instance.setsldpoint (this.sldpoint+sldincrement);
}
else {
Return alert (' not valid argument ' +direction);
}
Instance.applyarg ();
Instance.getsldpoint ();
}};
Neversliderbar.prototype.handleslddragstart=function () {with (this)
{
Sldbar.setcapture ();
Sldmoved = true;
Sldbar.onlosecapture = function () {sldmoved=false;};
Sldpoint = EVENT.CLIENTX-SLDBAROFFSET.L;
}};
Neversliderbar.prototype.handleslddrag=function () {with (this)
{
if (!sldmoved) return;
var p = event.clientx-sldpoint;
if (P <= sldobjoffset.l) {
SldBar.style.left = SLDOBJOFFSET.L;
}
else if (P >= (SLDOBJOFFSET.L+SLDOBJOFFSET.W-SLDBAROFFSET.W)) {
SldBar.style.left = SLDOBJOFFSET.L+SLDOBJOFFSET.W-SLDBAROFFSET.W;
}
else SldBar.style.left = p;
Instance.applyarg ();
Instance.getsldpoint ();
}};
Neversliderbar.prototype.handleslddragend=function () {with (this)
{
Sldbar.releasecapture ();
Sldmoved=false;
}};
function Offset (e) {
var t = e.offsettop;
var L = e.offsetleft;
var w = e.offsetwidth;
var h = e.offsetheight;
while (e=e.offsetparent) {
T+=e.offsettop;
L+=e.offsetleft;
}
return {t:t, l:l, W:w, h:h}
}


var r=new neversliderbar ("S1", Callback, ' <b>neverSliderBar</b> ');
r.sldmax=255;
R.setbtnstyle ("r-sliderbtn");
R.setbarstyle ("R-sliderbar");
R.setobjstyle ("R-sliderobj");
R.init ();
R.setsldpoint (100);
var g=new neversliderbar ("S2", Callback, ' <b>neverSliderBar</b> ');
g.sldmax=255;
G.setstyle ("G-sliderbar", "g-sliderbtn", "g-sliderobj");
G.init ();
G.setsldpoint (150);
var b=new neversliderbar ("S3", Callback, ' <b>neverSliderBar</b> ');
b.sldmax=255;
B.setbtnstyle ("b-sliderbtn");
B.setbarstyle ("B-sliderbar");
B.setobjstyle ("B-sliderobj");
B.setincrement (10);
B.init ();
B.setsldpoint (")";

Callback (' <b>neverSliderBar</b> ');
function callback (s) {
var $=document.getelementbyid;
var color_r=r.getsldpoint ();
var color_g=g.getsldpoint ();
var color_b=b.getsldpoint ();
$ ("color"). Style.backgroundcolor= "RGB" ("+color_r+", "+color_g+", "+color_b+") ";
$ ("D1"). Innerhtml=s+color_r;
$ ("D2"). Innerhtml=s+color_g;
$ ("D3"). Innerhtml=s+color_b;
}
-->
</SCRIPT>
<p>
Power by Never-online, Bluedestiny, http://www.never-online.net
</p>
</BODY>
</HTML>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.