JS Utilities
Started getheight function...seems not to work for now
This commit is contained in:
@@ -21,28 +21,28 @@ function findPos(obj) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function findPos2(element) {
|
//function findPos2(element) {
|
||||||
var bodyRect = document.body.getBoundingClientRect(),
|
// var bodyRect = document.body.getBoundingClientRect(),
|
||||||
elemRect = element.getBoundingClientRect(),
|
// elemRect = element.getBoundingClientRect(),
|
||||||
offset = elemRect.top - bodyRect.top;
|
// offset = elemRect.top - bodyRect.top;
|
||||||
|
//
|
||||||
|
// return []
|
||||||
|
//}
|
||||||
|
|
||||||
return []
|
//function findPos3(el) {
|
||||||
}
|
// var _x = 0;
|
||||||
|
// var _y = 0;
|
||||||
function findPos3(el) {
|
//
|
||||||
var _x = 0;
|
// while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
|
||||||
var _y = 0;
|
//
|
||||||
|
// _x += el.offsetLeft - el.scrollLeft;
|
||||||
while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
|
// _y += el.offsetTop - el.scrollTop;
|
||||||
|
//
|
||||||
_x += el.offsetLeft - el.scrollLeft;
|
// el = el.offsetParent;
|
||||||
_y += el.offsetTop - el.scrollTop;
|
// }
|
||||||
|
//
|
||||||
el = el.offsetParent;
|
// return {top: _y, left: _x};
|
||||||
}
|
//}
|
||||||
|
|
||||||
return {top: _y, left: _x};
|
|
||||||
}
|
|
||||||
|
|
||||||
//var x = getOffset( document.getElementById('header') ).left;
|
//var x = getOffset( document.getElementById('header') ).left;
|
||||||
|
|
||||||
@@ -82,20 +82,20 @@ function class_By_Y_Position($id, $activeclass, $inactiveclass, $startoffset, $e
|
|||||||
runOnScroll = function () {
|
runOnScroll = function () {
|
||||||
var $scrollpos = window.scrollY;
|
var $scrollpos = window.scrollY;
|
||||||
|
|
||||||
console.log('scrollposition');
|
//console.log('scrollposition');
|
||||||
|
//
|
||||||
|
//
|
||||||
console.log($scrollpos);
|
//console.log($scrollpos);
|
||||||
|
//
|
||||||
console.log('offsets');
|
//console.log('offsets');
|
||||||
console.log($startoffset);
|
//console.log($startoffset);
|
||||||
console.log($endoffset);
|
//console.log($endoffset);
|
||||||
|
//
|
||||||
console.log('calcpositions');
|
//console.log('calcpositions');
|
||||||
console.log($start);
|
//console.log($start);
|
||||||
console.log($end);
|
//console.log($end);
|
||||||
|
//
|
||||||
console.log('positions');
|
//console.log('positions');
|
||||||
|
|
||||||
// Check if we are beyond the startpoint
|
// Check if we are beyond the startpoint
|
||||||
if ($scrollpos > $start) {
|
if ($scrollpos > $start) {
|
||||||
@@ -145,6 +145,7 @@ function class_By_Y_Position($id, $activeclass, $inactiveclass, $startoffset, $e
|
|||||||
|
|
||||||
console.log("Start" + $start);
|
console.log("Start" + $start);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case false:
|
case false:
|
||||||
$start = ($elementtop + $startoffset);
|
$start = ($elementtop + $startoffset);
|
||||||
$end = ($elementtop + $endoffset);
|
$end = ($elementtop + $endoffset);
|
||||||
@@ -163,4 +164,20 @@ function class_By_Y_Position($id, $activeclass, $inactiveclass, $startoffset, $e
|
|||||||
document.addEventListener("resize", runOnScroll);
|
document.addEventListener("resize", runOnScroll);
|
||||||
|
|
||||||
window.addEventListener("scroll", runOnScroll);
|
window.addEventListener("scroll", runOnScroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getheight($selector) {
|
||||||
|
$identifier = $selector.substr(0, 1);
|
||||||
|
|
||||||
|
if ($identifier === ".") {
|
||||||
|
return $element = document.getElementsByClassName(
|
||||||
|
$selector.substr(1))[0].getBoundingClientRect().height;
|
||||||
|
}
|
||||||
|
else if ($identifier === "#") {
|
||||||
|
return $element = document.getElementById(
|
||||||
|
$selector.substr(1)).getBoundingClientRect().height;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Error identifying selector type!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user