以下是 jQuery鼠标滚轮滚动条代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>jQuery鼠标滚轮滚动条代码</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/scrollbar.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="jquery/jquery.ba-resize.min.js"></script>
<script src="js/pngFixer.js"></script>
<script src="js/scrollbar.min.js"></script>
<script src="js/buttons.js"></script>
</head>
<body>
<div id="main">
<div id="center">
<div id="scrollbar1">
<div class="scrollbar">
<div class="content">
<img src="images/kung-fu-panda-original.jpg" />
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
<h4>The standard Lorem Ipsum passage</h4>
<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>
<img src="images/2008_kung_fu_panda_008.jpg" />
</div>
</div>
</div><br />
</div>
</div>
</body>
</html>
JS代码(jquery.mousewheel.min.js):
/* Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net) * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * Thanks to:http://adomas.org/javascript-mouse-wheel/ for some pointers. * Thanks to:Mathias Bank(http://www.mathias-bank.de) for a scope bug fix. * * Version:3.0.2 * * Requires:1.2.2+ */
(function(c){
var a=["DOMMouseScroll","mousewheel"];
c.event.special.mousewheel={
setup:function(){
if(this.addEventListener){
for(var d=a.length;
d;
){
this.addEventListener(a[--d],b,false)}
}
else{
this.onmousewheel=b}
}
,teardown:function(){
if(this.removeEventListener){
for(var d=a.length;
d;
){
this.removeEventListener(a[--d],b,false)}
}
else{
this.onmousewheel=null}
}
}
;
c.fn.extend({
mousewheel:function(d){
return d?this.bind("mousewheel",d):this.trigger("mousewheel")}
,unmousewheel:function(d){
return this.unbind("mousewheel",d)}
}
);
function b(f){
var d=[].slice.call(arguments,1),g=0,e=true;
f=c.event.fix(f||window.event);
f.type="mousewheel";
if(f.wheelDelta){
g=f.wheelDelta/120}
if(f.detail){
g=-f.detail/3}
d.unshift(f,g);
return c.event.handle.apply(this,d)}
}
)(jQuery);
JS代码(pngFixer.js):
function fnFixPng($obj){
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent){
var bg= $obj.css("background-image");
var src = bg.substring(5,bg.length-2);
$obj.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')");
$obj.css("background-image","url(x.gif)");
}
}
CSS代码(main.css):
@font-face{font-family:'AvantGardeBkBTBook';src:url('../fonts/avant_garde_book_bt-webfont.eot');src:url('../fonts/avant_garde_book_bt-webfont.eot?#iefix') format('embedded-opentype'),url('../fonts/avant_garde_book_bt-webfont.woff') format('woff'),url('../fonts/avant_garde_book_bt-webfont.ttf') format('truetype'),url('../fonts/avant_garde_book_bt-webfont.svg#AvantGardeBkBTBook') format('svg');font-weight:normal;font-style:normal;}
@font-face{font-family:'BentonSansExtraCompRegular';src:url('../fonts/bentonsansextracomp-regular-webfont.eot');src:url('../fonts/bentonsansextracomp-regular-webfont.eot?#iefix') format('embedded-opentype'),url('../fonts/bentonsansextracomp-regular-webfont.woff') format('woff'),url('../fonts/bentonsansextracomp-regular-webfont.ttf') format('truetype'),url('../fonts/bentonsansextracomp-regular-webfont.svg#BentonSansExtraCompRegular') format('svg');font-weight:normal;font-style:normal;}
*{margin:0;padding:0;text-decoration:none;border:none;}
body{background-color:#0e0e0e;background-image:url(../images/preview/grid13.png);background-repeat:repeat;}
#main{padding-top:20px;background-color:#ffffff;width:900px;margin:30px auto;-moz-border-radius:4px;-webkit-border-radius:4px;-khtml-border-radius:4px;border-radius:3px;border:solid;border-color:#e9e9e9;border-width:3px;}
#center{width:802px;margin:0px auto;}
#header{width:802px;margin:0px auto;padding-top:20px;padding-bottom:30px;}
#footer{font-family:Arial,Helvetica,sans-serif;font-size:14px;color:#333333;width:802px;margin:0px auto;margin-bottom:20px;}
#social_links{right:0px;margin-top:-10px;height:30px;float:right;}
#social_links .social_button{height:30px;width:30px;position:relative;margin:0 3px;float:left;}
#social_links .social_button span.hover{height:30px;width:30px;position:absolute;}
div.example{padding-bottom:30px;padding-top:30px;border-bottom:solid;border-bottom-color:#CCCCCC;border-bottom-width:1px;}
div.example .imageEx{margin-bottom:5px;border:solid;border-color:#cccccc;border-width:1px;}
div.active{opacity:0.5;}
div.notActive{-webkit-transition:opacity 0.3s ease-out;-moz-transition:opacity 0.3s ease-out;transition:opacity 0.3s ease-out;opacity:1;}
div.notActive:hover{opacity:0.9;}
h1{text-align:right;padding-top:20px;padding-bottom:20px;font-family:"BentonSansCompRegular";font-size:29px;color:#080808;border-bottom:solid;border-bottom-color:#CCCCCC;border-bottom-width:1px;border-top:solid;border-top-color:#CCCCCC;border-top-width:1px;}
h1 span{font-size:18px;color:#a1dc13;}
h1 img{float:left;position:relative;top:-12px;}
p{color:#333333;font-family:Arial,Helvetica,sans-serif;font-size:15px;padding-top:10px;padding-bottom:10px;padding-left:10px;padding-right:10px;margin-bottom:20px;margin-top:10px;}
p.box{border-bottom:dotted;border-bottom-color:#CCCCCC;border-bottom-width:1px;border-top:dotted;border-top-color:#CCCCCC;border-top-width:1px;}
h2{font-family:'BentonSansExtraCompRegular';font-size:35px;color:#080808;border-bottom:solid;border-bottom-color:#CCCCCC;border-bottom-width:1px;margin-top:50px;margin-bottom:15px;padding-left:10px;padding-right:10px;}
h2 span{color:#a1dc13;}
h3{font-family:'BentonSansExtraCompRegular';font-size:30px;color:#080808;margin-top:10px;padding-left:10px;padding-right:10px;}
h4{font-family:'BentonSansCompRegular';font-size:23px;color:#080808;margin-top:10px;padding-left:10px;padding-right:10px;}