Skip to content

Commit

Permalink
3.1.9 - fix z-index and scrolling enhancement
Browse files Browse the repository at this point in the history
New options
- nativeparentscrolling (default:true), detect bottom of content and let parent to scroll, as native scroll does - close inuyaksa#176

Changed features
- Smoothest scrolling with mousewheel

Fixes
- zindex=auto, recurve check for use correct zindex value - fixes inuyaksa#149
- horiz scrollbar position issue - fixes inuyaksa#154
  • Loading branch information
inuyaksa committed Mar 24, 2013
1 parent ca4fdc9 commit e15a3d0
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 262 deletions.
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jquery.nicescroll
v. 3.1.8 03-18-2013
v. 3.1.9 03-24-2013
copyright 2011-12-13 InuYaksa*2013
licensed under the MIT
http://nicescroll.areaaperta.com
Expand Down Expand Up @@ -158,6 +158,7 @@ When you call "niceScroll" you can pass some parameters to custom visual aspects
. cursorfixedheight, set fixed height for cursor in pixel (default:false)
. hidecursordelay, set the delay in microseconds to fading out scrollbars (default:400)
. directionlockdeadzone, dead zone in pixels for direction lock activation (default:6)
. nativeparentscrolling , detect bottom of content and let parent to scroll, as native scroll does (default:true)

* LICENSE

Expand Down
23 changes: 0 additions & 23 deletions changelog_3.1.8.txt

This file was deleted.

15 changes: 15 additions & 0 deletions changelog_3.1.9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Changelog nicescroll release 3.1.9
http://nicescroll.areaaperta.com/
https://github.com/inuyaksa/jquery.nicescroll

New options
- nativeparentscrolling (default:true), detect bottom of content and let parent to scroll, as native scroll does - close #176


Changed features
- Smoothest scrolling with mousewheel


Fixes
- zindex=auto, recurve check for use correct zindex value - fixes #149
- horiz scrollbar position issue - fixes #154
208 changes: 104 additions & 104 deletions demo/js/jquery.nicescroll.min.js

Large diffs are not rendered by default.

98 changes: 69 additions & 29 deletions jquery.nicescroll.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* jquery.nicescroll
-- version 3.1.8
-- version 3.1.9
-- copyright 2011-12-13 InuYaksa*2013
-- licensed under the MIT
--
Expand Down Expand Up @@ -84,7 +84,8 @@
// cursormaxheight:false,
cursorfixedheight:false,
directionlockdeadzone:6,
hidecursordelay:400
hidecursordelay:400,
nativeparentscrolling:true
}

var browserdetected = false;
Expand Down Expand Up @@ -191,7 +192,7 @@

var self = this;

this.version = '3.1.8';
this.version = '3.1.9';
this.name = 'nicescroll';

this.me = me;
Expand Down Expand Up @@ -284,6 +285,7 @@
this.cursoractive = true; // user can interact with cursors

this.nativescrollingarea = false;
this.checkarea = 0;

this.events = []; // event list for unbind

Expand Down Expand Up @@ -343,6 +345,15 @@
}
};

this.debounced = function(name,fn,tm) {
var dd = self.delaylist[name];
var nw = (new Date()).getTime();
self.delaylist[name] = fn;
if (!dd) {
setTimeout(function(){var fn=self.delaylist[name];self.delaylist[name]=false;fn.call();},tm);
}
}

this.synched = function(name,fn) {

function requestSync() {
Expand Down Expand Up @@ -527,6 +538,18 @@
return (el!==false);
};

function getZIndex() {
var dom = self.win;
if ("zIndex" in dom) return dom.zIndex(); // use jQuery UI method when available
while (dom.length>0) {
if (dom[0].nodeType==9) return false;
var zi = dom.css('zIndex');
if (!isNaN(zi)&&zi!=0) return zi;
dom = dom.parent();
}
return false;
};

//inspired by http://forum.jquery.com/topic/width-includes-border-width-when-set-to-thin-medium-thick-in-ie
var _convertBorderWidth = {"thin":1,"medium":3,"thick":5};
function getWidthToPixel(dom,prop,chkheight) {
Expand Down Expand Up @@ -628,8 +651,7 @@

self.zindex = "auto";
if (!self.ispage&&self.opt.zindex=="auto") {
var zi = self.win.prop('zIndex');
if (!isNaN(zi)) self.zindex = zi;
self.zindex = getZIndex();
} else {
self.zindex = self.opt.zindex;
}
Expand Down Expand Up @@ -737,7 +759,7 @@
var railh = $(document.createElement('div'));
railh.attr('id',self.id+'-hr');
railh.addClass('nicescroll-rails');
railh.height = 1+Math.max(parseFloat(self.opt.cursorwidth),cursor.outerHeight());
railh.height = Math.max(parseFloat(self.opt.cursorwidth),cursor.outerHeight());
railh.css({height:railh.height+"px",'zIndex':self.zindex,"background":self.opt.background});

railh.append(cursor);
Expand Down Expand Up @@ -1244,9 +1266,12 @@
}
});
return self.cancelEvent(e);
} else {
}
/*
else {
self.checkarea = true;
}
*/

};
}
Expand Down Expand Up @@ -1984,7 +2009,7 @@
return false;
};

function execScrollWheel(e,hr) {
function execScrollWheel(e,hr,chkscroll) {
var px = 0;
var py = 0;
var rt = 1;
Expand All @@ -2005,50 +2030,65 @@
if (px) {
if (self.scrollmom) {self.scrollmom.stop()}
self.lastdeltax+=px;
self.synched("mousewheelx",function(){var dt=self.lastdeltax;self.lastdeltax=0;if(!self.rail.drag){self.doScrollLeftBy(dt)}});
self.debounced("mousewheelx",function(){var dt=self.lastdeltax;self.lastdeltax=0;if(!self.rail.drag){self.doScrollLeftBy(dt)}},120);
}
if (py) {
if (self.opt.nativeparentscrolling&&chkscroll) {
if (py<0) {
if (self.getScrollTop()>=self.page.maxh) return true;
} else {
if (self.getScrollTop()<=0) return true;
}
}
if (self.scrollmom) {self.scrollmom.stop()}
self.lastdeltay+=py;
self.synched("mousewheely",function(){var dt=self.lastdeltay;self.lastdeltay=0;if(!self.rail.drag){self.doScrollBy(dt)}});
}
self.debounced("mousewheely",function(){var dt=self.lastdeltay;self.lastdeltay=0;if(!self.rail.drag){self.doScrollBy(dt)}},120);
}
return self.cancelEvent(e);
};

this.onmousewheel = function(e) {
if (self.locked) return true;
if (self.rail.drag) return self.cancelEvent(e);

if (!self.rail.scrollable) {
if (self.railh&&self.railh.scrollable) {
return self.onmousewheelhr(e);
} else {
return true;
}
}
if (self.opt.preservenativescrolling&&self.checkarea) {
self.checkarea = false;
self.nativescrollingarea = self.isScrollable(e);
var nw = +(new Date());
var chk = false;
if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
// self.checkarea = false;
self.nativescrollingarea = self.isScrollable(e);
chk = true;
}
self.checkarea = nw;
if (self.nativescrollingarea) return true; // this isn't my business
if (self.locked) return self.cancelEvent(e);
if (self.rail.drag) return self.cancelEvent(e);

execScrollWheel(e,false);

return self.cancelEvent(e);
// if (self.locked) return self.cancelEvent(e);
var ret = execScrollWheel(e,false,chk);
if (ret) self.checkarea = 0;
return ret;
};

this.onmousewheelhr = function(e) {
if (self.locked||!self.railh.scrollable) return true;
if (self.opt.preservenativescrolling&&self.checkarea) {
self.checkarea = false;
if (self.rail.drag) return self.cancelEvent(e);

var nw = +(new Date());
var chk = false;
if (self.opt.preservenativescrolling&&((self.checkarea+600)<nw)) {
// self.checkarea = false;
self.nativescrollingarea = self.isScrollable(e);
chk = true;
}
self.checkarea = nw;
if (self.nativescrollingarea) return true; // this isn't my business
if (self.locked) return self.cancelEvent(e);
if (self.rail.drag) return self.cancelEvent(e);

execScrollWheel(e,true);

return self.cancelEvent(e);
return execScrollWheel(e,true,chk);
};

this.stop = function() {
Expand Down Expand Up @@ -2760,7 +2800,7 @@

var _scrollTop = jQuery.fn.scrollTop; // preserve original function

$.cssHooks["pageYOffset"] = {
jQuery.cssHooks["pageYOffset"] = {
get: function(elem,computed,extra) {
var nice = $.data(elem,'__nicescroll')||false;
return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(elem);
Expand All @@ -2771,14 +2811,14 @@
return this;
}
};

/*
$.fx.step["scrollTop"] = function(fx){
$.cssHooks["scrollTop"].set( fx.elem, fx.now + fx.unit );
};
*/

jQuery.fn.scrollTop = function(value) {
jQuery.fn.scrollTop = function(value) {
if (typeof value == "undefined") {
var nice = (this[0]) ? $.data(this[0],'__nicescroll')||false : false;
return (nice&&nice.ishwscroll) ? nice.getScrollTop() : _scrollTop.call(this);
Expand Down
Loading

0 comments on commit e15a3d0

Please sign in to comment.