Your method used as an example is that it is the problem, offsetTop
is a get
method, not set
. That is, with it you can only get values and not declare them or change them. In this case, as offsetTop
captures top
of the element in question (in pixels), the maximum you can do to change it is through css :
document.getElementById("stars").style.top = valor
// O propriedade top só pode ser usada após a declaraçã o da propriedade position...
But you can change the "attributes" by javascript, for example with the scrollTop
method. See in this example:
console.log(document.getElementById("stars").scrollTop); // retornará 0
document.getElementById("stars").scrollTop = 10;
console.log(document.getElementById("stars").scrollTop); // retornará 10
The scrollTop
yes method is a get/set
method. With it you capture and determine values.