Storing values in Javascript elements - Good practices

Asked

Viewed 24 times

1

I wonder if it is good practice to store values directly in the elements so you don’t need to calculate again. For example:

function scrollfunc(e){
    var el = e.currentTarget;
    var deltaY = (el.deltaY !== undefined)? (el.deltaY + e.y) : e.y;

    el.style.transform = 'translateY(' + deltaY + 'px)';
    el.deltaY = deltaY;
}

document.getElementById('#scrollElement').addEventListener(scrollfunc);
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.