mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-30 11:10:24 +00:00
fixed scrolling bug on non-webkit based browsers
This commit is contained in:
parent
56c412d2a0
commit
356d9586c2
3 changed files with 63 additions and 32 deletions
|
|
@ -47,38 +47,66 @@ var CloudCommander, $;
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
lUtil.scrollIntoViewIfNeeded = function(el){
|
||||
/*
|
||||
* http://www.performantdesign.com/2009/08/26/scrollintoview-but-only-if-out-of-view/
|
||||
*/
|
||||
var topOfPage = window.pageYOffset ||
|
||||
document.documentElement.scrollTop ||
|
||||
document.body.scrollTop;
|
||||
/* function polyfill webkit standart function */
|
||||
lUtil.scrollIntoViewIfNeeded = function(pElement, centerIfNeeded){
|
||||
/*
|
||||
https://gist.github.com/2581101
|
||||
*/
|
||||
centerIfNeeded = arguments.length === 0 ? true : !!centerIfNeeded;
|
||||
|
||||
var heightOfPage = window.innerHeight ||
|
||||
document.documentElement.clientHeight ||
|
||||
document.body.clientHeight;
|
||||
var parent = pElement.parentNode,
|
||||
parentComputedStyle = window.getComputedStyle(parent, null),
|
||||
parentBorderTopWidth =
|
||||
parseInt(parentComputedStyle.getPropertyValue('border-top-width')),
|
||||
|
||||
parentBorderLeftWidth =
|
||||
parseInt(parentComputedStyle.getPropertyValue('border-left-width')),
|
||||
|
||||
overTop = pElement.offsetTop - parent.offsetTop < parent.scrollTop,
|
||||
overBottom =
|
||||
(pElement.offsetTop -
|
||||
parent.offsetTop +
|
||||
pElement.clientHeight -
|
||||
parentBorderTopWidth) >
|
||||
(parent.scrollTop + parent.clientHeight),
|
||||
|
||||
overLeft = pElement.offsetLeft -
|
||||
parent.offsetLeft < parent.scrollLeft,
|
||||
|
||||
overRight =
|
||||
(pElement.offsetLeft -
|
||||
parent.offsetLeft +
|
||||
pElement.clientWidth -
|
||||
parentBorderLeftWidth) >
|
||||
(parent.scrollLeft + parent.clientWidth),
|
||||
|
||||
alignWithTop = overTop && !overBottom;
|
||||
|
||||
var elY = 0;
|
||||
var elH = 0;
|
||||
if ((overTop || overBottom) && centerIfNeeded) {
|
||||
parent.scrollTop =
|
||||
pElement.offsetTop -
|
||||
parent.offsetTop -
|
||||
parent.clientHeight / 2 -
|
||||
parentBorderTopWidth +
|
||||
pElement.clientHeight / 2;
|
||||
}
|
||||
|
||||
if (document.layers) { // NS4
|
||||
elY = el.y;
|
||||
elH = el.height;
|
||||
}
|
||||
else {
|
||||
for(var p = el; p && p.tagName != 'BODY'; p = p.offsetParent)
|
||||
elY += p.offsetTop;
|
||||
|
||||
elH = el.offsetHeight;
|
||||
}
|
||||
if ((overLeft || overRight) && centerIfNeeded) {
|
||||
parent.scrollLeft =
|
||||
pElement.offsetLeft -
|
||||
parent.offsetLeft -
|
||||
parent.clientWidth / 2 -
|
||||
parentBorderLeftWidth +
|
||||
pElement.clientWidth / 2;
|
||||
}
|
||||
|
||||
if ((topOfPage + heightOfPage) < (elY + elH))
|
||||
el.scrollIntoView(false);
|
||||
|
||||
else if (elY < topOfPage)
|
||||
el.scrollIntoView(true);
|
||||
};
|
||||
if (( overTop ||
|
||||
overBottom ||
|
||||
overLeft ||
|
||||
overRight) &&
|
||||
!centerIfNeeded) {
|
||||
pElement.scrollIntoView(alignWithTop);
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue