JavaScript Instance Tutorial: Custom scroll bars for mouse events

Source: Internet
Author: User
Tags object interface range return window

Article Introduction: Object-oriented-custom scroll bar, with mouse events, an estimated error is many.

Object-oriented-custom scroll bar, with the mouse event; it's a lot of mistakes.

<! DOCTYPE html>



<meta charset= "UTF-8" >

<title></title>

<style type= "Text/css" >

*{margin:0;padding:0;}

#div1 {width:30px; height:400px; background:red;position:relative;top:30px; left:30px;}

#div2 {width:30px; height:30px; Background:blue;position:absolute}

#div3 {width:300px; height:400px;border:1px solid blue;position:absolute;left:100px;top:30px; overflow:hidden;}

#div4 {position:absolute;top:0;left:0;}

</style>

<script type= "Text/javascript" >

Window.onload=function ()

{

var obj= new Zhailei ("div")

}

function Zhailei (ID)

{

var _this=this;

This.odiv1 =document.getelementbyid (id+ "1");

This.odiv2 =document.getelementbyid (id+ "2");

This.odiv3 =document.getelementbyid (id+ "3");

This.odiv4 =document.getelementbyid (id+ "4");

this.disy=0;

This.obtn=true;

this.odiv2.style.height=this.odiv3.offsetheight/this.odiv4.offsetheight*this.odiv1.offsetheight+ "px";

This.odiv2.onmousedown=function (EV)

{

_this.fndown (EV);

}

if (This.oDiv1.addEventListener)

{

This.oDiv1.addEventListener ("Dommousescroll", function (EV) {_this.torun (EV)},false);

This.oDiv4.addEventListener ("Dommousescroll", function (EV) {_this.torun (EV)},false);

};

This.odiv1.onmousewheel=function (EV)

{

_this.torun (EV)

};

This.odiv4.onmousewheel=function (EV)

{

_this.torun (EV)

};

}

Zhailei.prototype.torun=function (EV)

{

var ev = EV window.event

this.abc=0;

if (Ev.detail)

{

this.obtn=ev.detail>0?true:false;

}

Else

{

this.obtn=ev.wheeldelta<0?true:false;

}

if (THIS.OBTN)

{

This.abc=this.odiv2.offsettop + 10

}

Else

{

This.abc= this.odiv2.offsettop-10;

}

if (this.abc<0)

{

THIS.ABC = 0;

}

else if (this.abc>this.odiv1.offsetheight-this.odiv2.offsetheight)

{

THIS.ABC = This.odiv1.offsetheight-this.odiv2.offsetheight;

}

This.oDiv2.style.top = this.abc + ' px ';

This.soley = this.abc/(this.odiv1.offsetheight-this.odiv2.offsetheight);

This.oDiv4.style.top =-This.soley * (this.odiv4.offsetheight-this.odiv3.offsetheight) + ' px ';

if (Ev.preventdefault)

{

Ev.preventdefault ()

}

return False

}

Zhailei.prototype.fndown=function (EV)

{

var _this =this

var ev = EV window.event;

This.disy=ev.clienty-this.odiv2.offsettop

if (this.oDiv2.setCapture)

{

This.oDiv2.setCapture ()

}

Document.onmousemove=function (EV)

{

_this.fnmove (EV)

}

Document.onmouseup=function ()

{

_this.fnup ()

}

}

Zhailei.prototype.fnmove=function (EV)

{

var ev = EV window.event;

This.gomove (EV)

}

Zhailei.prototype.fnup=function ()

{

Document.onmousemove=null;

Document.onmouseup=null;

if (this.oDiv2.releaseCapture)

{

This.oDiv2.releaseCapture ()

}

}

Zhailei.prototype.gomove=function (EV)

{

This.abc=ev.clienty-this.disy;

if (this.abc<0)

{

this.abc=0;

}

else if (this.abc>this.odiv1.offsetheight-this.odiv2.offsetheight)

{

This.abc=this.odiv1.offsetheight-this.odiv2.offsetheight;

}

this.odiv2.style.top=this.abc+ "px";

this.scrollx=this.abc/(This.odiv1.offsetheight-this.odiv2.offsetheight);

document.title=-this.scrollx* (this.odiv4.offsetheight-this.odiv3.offsetheight) + "px";

this.odiv4.style.top=-this.scrollx* (this.odiv4.offsetheight-this.odiv3.offsetheight) + "px";

if (Ev.preventdefault)

{

Ev.preventdefault ()

}

return False

}

</script>


<body>

<div id= "Div1" >

<div id= "Div2" ></div>

</div>

<div id= "Div3" >

<div id= "Div4" >

Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object-oriented (Object Oriented,oo) is the focus of the current computer industry, it is the 90 's software development sideThe mainstream of law. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database system, interactive interface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields. Object Oriented,oo is the focus of the current computer industry, it is the mainstream of software development method in the 90 's. Object-oriented concepts and applications have gone beyond programming and software development, extending to a wide range. such as database systems, interactiveinterface, application structure, application platform, distributed system, network management structure, CAD technology, artificial intelligence and other fields.

</div>

</div>

</body>



Related Article

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.