JS Utilities

Started getheight function...seems not to work for now
This commit is contained in:
2017-05-31 16:40:12 +02:00
parent 09a00d2c83
commit 092abd4c5b
+52 -35
View File
@@ -21,28 +21,28 @@ function findPos(obj) {
}
}
function findPos2(element) {
var bodyRect = document.body.getBoundingClientRect(),
elemRect = element.getBoundingClientRect(),
offset = elemRect.top - bodyRect.top;
//function findPos2(element) {
// var bodyRect = document.body.getBoundingClientRect(),
// elemRect = element.getBoundingClientRect(),
// offset = elemRect.top - bodyRect.top;
//
// return []
//}
return []
}
function findPos3(el) {
var _x = 0;
var _y = 0;
while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
return {top: _y, left: _x};
}
//function findPos3(el) {
// var _x = 0;
// var _y = 0;
//
// while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) {
//
// _x += el.offsetLeft - el.scrollLeft;
// _y += el.offsetTop - el.scrollTop;
//
// el = el.offsetParent;
// }
//
// return {top: _y, left: _x};
//}
//var x = getOffset( document.getElementById('header') ).left;
@@ -82,20 +82,20 @@ function class_By_Y_Position($id, $activeclass, $inactiveclass, $startoffset, $e
runOnScroll = function () {
var $scrollpos = window.scrollY;
console.log('scrollposition');
console.log($scrollpos);
console.log('offsets');
console.log($startoffset);
console.log($endoffset);
console.log('calcpositions');
console.log($start);
console.log($end);
console.log('positions');
//console.log('scrollposition');
//
//
//console.log($scrollpos);
//
//console.log('offsets');
//console.log($startoffset);
//console.log($endoffset);
//
//console.log('calcpositions');
//console.log($start);
//console.log($end);
//
//console.log('positions');
// Check if we are beyond the startpoint
if ($scrollpos > $start) {
@@ -145,6 +145,7 @@ function class_By_Y_Position($id, $activeclass, $inactiveclass, $startoffset, $e
console.log("Start" + $start);
break;
case false:
$start = ($elementtop + $startoffset);
$end = ($elementtop + $endoffset);
@@ -163,4 +164,20 @@ function class_By_Y_Position($id, $activeclass, $inactiveclass, $startoffset, $e
document.addEventListener("resize", 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!")
}
}