Trying to ask a question in English when only having half knowledge of the language can be quite confusing. Therefore, I aim to create a function that can differentiate between a single node or a collection of nodes as its parameter and then retrieve the data from the respective node/nodes. Demonstrating this functionality would make it clearer than explaining it. Please forgive any mistakes in my English or JavaScript, as well as the lengthy explanation of my issue.
var e, eH;
function x(y){
e = y;
eH = e.offsetHeight;
};
var ps = document.querySelectorAll("p");
x(ps);
e.style.top = `${eH}px`;
For instance, if I want to set the top style property based on the height of an element, but 'ps' represents a collection of nodes.
var e, eH, i = 0;
function x(y){
e = y;
eH = e.offsetHeight;
howmany(e)
};
function howmany(z){
e = z;
if (e[i] !== undefined){
for (i; i<e.length; i++){
e = e[i]
}
};
var ps = document.querySelectorAll("p");
x(ps);
e.style.top = `${eH}px`;
var i,a;
function fun(e){
i = 0;
a = e;
if (e[i] === undefined){
a+=1
}
else{
for (i; i<e.length; i++){
a[i]+=1;
}
}
};
var x = [1,2,3,4,5];
fun(x);
var e, eH, i = 0;
function x(y, whattodo){
e = y;
eH = e.offsetHeight;
c = whattodo
howmany(e, c)
};
function howmany(z, v){
e = z;
if (e[i] !== undefined){
for (i; i<e.length; i++){
e[i].v
}
};
var ps = document.querySelectorAll("p"),
var wtd = style.top = `${eH}px`;
x(ps, wtd);
If my objective is to set a specific property for one or multiple elements, that method would be ideal, but it's not what I'm aiming for. My goal is to be able to "control" each individual element within a node collection when calling the function. Describing my problem in words seems impossible, so let me illustrate with a real example. Here's the code:
var elem, celElem, elemTop, elemMag, elemBot, elemCent, winTop, winMag, winBot, winCent;
function getElem(el, cEl){
elem = el,
celElem = cEl,
elemTop = 0,
elemMag = elem.offsetHeight,
elemBot = elemTop+elemMag,
elemCent = elemTop+(elemMag/2),
winTop = window.pageYOffset,
winMag = window.innerHeight,
winBot = winTop+winMag,
winCent = winTop+(winMag/2),
if (celElem === undefined){celElem = elem};
topMag(elem);
};
function topMag(x){
elem = x;
if (getComputedStyle(elem).position === "fixed"){
elemTop = elem.offsetTop;
}
else{
do{
elemTop += elem.offsetTop;
elem = elem.offsetParent;
}
while(elem != "[object HTMLBodyElement]");
elem = x;
}
};
var targetElem = document.querySelectorAll("p");
var nagyElemCent = -Math.abs((winCent-elemCent)/((elemMag+winMag)/2))+1;
getElem(targetElem);
elem.style.opacity = nagyElemCent;
This example should paint a clearer picture of my predicament. What I desire is when setting 'elem' in the final line of code, it refers to all the paragraphs. While I have predefined values like 'nagyElemCent', they often require modifications to achieve the desired outcome.