From 092abd4c5b6e61b7f43889c982404c40413bfe68 Mon Sep 17 00:00:00 2001 From: simongehrig Date: Wed, 31 May 2017 16:40:12 +0200 Subject: [PATCH] JS Utilities Started getheight function...seems not to work for now --- element-position/element-position.js | 87 +++++++++++++++++----------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/element-position/element-position.js b/element-position/element-position.js index 728e8cc..d6096e1 100644 --- a/element-position/element-position.js +++ b/element-position/element-position.js @@ -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!") + } } \ No newline at end of file