Coding with JavaScript
var changeHeight = () => {
let flag = 0;
while(flag != 1) {
size += 1;
return size;
}
if(size == window.innerHeight/2){
flag == 1;
}
}
var size = 5;
document.body.style.height = "10000px";
const div = document.createElement("div");
div.style.width = "100%";
div.style.position = "fixed";
div.style.left = "0";
div.style.top = "0";
div.style.backgroundColor = "green";
document.body.appendChild(div);
window.addEventListener("scroll", changeHeight);
div.style.height = size + "px";
HTML Learning
There is little content, only
<script src="script1.js"> </script>
inside it.
What am I aiming for?
The objective is to make an element stick to the top of the page as the user scrolls, expanding in height until it reaches window.innerHeight/2
. Once this limit is reached, the scrolling should reduce its size.
I'm encountering issues with returning the 'size' variable within the function. Could there be another error in my code?