'use strict';
//下面别动
function myapi(){
this.mousescroll = {
inte : function(obj,value){
this.obj = obj;
this.addscroll(obj);
var outh = obj.outerheight(),
oscrollcontent = obj.children(':first'),
contenth = oscrollcontent.outerheight(),
oyscrollinnerh = outh/contenth*outh,
oyscrollouter = obj.find('#yscrollouter'),
oyscrollinner = obj.find('#yscrollinner');
obj.css({'position': 'relative','overflow':'auto'});
oscrollcontent.css('position', 'absolute');
if(contenth > outh){
this.mousehover(obj, oyscrollouter, oyscrollinner);
this.mousewheel(obj, value, oscrollcontent, oyscrollinner, outh, contenth, oyscrollinnerh );
this.mousemoved(obj, oscrollcontent, oyscrollouter, oyscrollinner, outh, contenth, oyscrollinnerh );
};
},
addscroll : function(obj,value){
obj.append('
');
$('#yscrollinner').css('cursor','pointer');
},
mousehover : function(obj, outer, inner){
obj.hover(function() {
outer.fadein(400);
}, function() {
outer.fadeout(400);
});
inner.hover(function() {
$('body').css({
'-moz-user-select': 'auto',
'-webkit-user-select': 'auto',
'-ms-user-select': 'auto',
'-khtml-user-select': 'auto',
'user-select': 'auto',});
}, function() {
$('body').css({
'-moz-user-select': 'auto',
'-webkit-user-select': 'auto',
'-ms-user-select': 'auto',
'-khtml-user-select': 'auto',
'user-select': 'auto',});
});
},
mousewheel : function(obj, value, o, inner, h1, h2, h3){
var oscrollcontentval = value/(h1 - h3)*(h2 - h1);
inner.height(h3); //滚动条高度
obj.on('mousewheel',function(event,delta ){ //绑定滚轮事件
event.preventdefault(); //阻止浏览器默认为行
var delta = event.originalevent.wheeldelta;
var oyscrollinnertop = inner.position().top;
var oscrollcontenttop = o.position().top;
if(delta > 0){
if(oyscrollinnertop - value < 0){
inner.css('top', 0);
o.css('top', 0);
}else{
inner.css('top', oyscrollinnertop - value);
o.css('top', oscrollcontenttop + oscrollcontentval);
}
}else{
if(oyscrollinnertop + value > h1 - h3){
inner.css('top', h1 - h3);
o.css('top', h1 - h2);
}else{
inner.css('top', oyscrollinnertop + value);
o.css('top', oscrollcontenttop - oscrollcontentval);
}
};
});
},
mousemoved : function(obj, o, outer, inner, h1, h2, h3){
inner.on('mousedown',function(event){ //绑定鼠标事件
var clienty = event.clienty,
oyscrollinnertop = inner.position().top,
oscrollcontenttop = o.position().top,
movey = 0;
$(document).on('mousemove',function(event){
movey = event.clienty - clienty;
var oscrollcontentmove = movey/(h1 - h3)*(h2 - h1);
if(oyscrollinnertop + movey < 0){
inner.css('top', 0);
o.css('top', 0);
}else if(oyscrollinnertop + movey > h1 - h3){
inner.css('top', h1 - h3);
o.css('top', h1 - h2);
}else{
inner.css('top', oyscrollinnertop + movey);
o.css('top', oscrollcontenttop - oscrollcontentmove);
}
});
$(document).on('mouseup',function(event){
$(document).off('mousemove');
})
})
}
}
}