I am currently learning javascript and have encountered a problem that got me stuck:
I have a div with a 90% height and a 80% width.
I'm trying to make this div grow when scrolling to reach a full screen size (needs to occupy the whole display)(100% width, 100% height).
I've tried for and do-while loops, but it doesn't seem to be working.
It seems as if the height and width of the div do not change the element's style.
Does anyone know how to fix this ?
I am really looking forwards to any tips you can give me in order to achieve my project and learn from my mistakes.
Below is my current code :
$(document).ready(function(){
$(window).scroll(function(e){
var pos = $(window).scrollTop();
console.log("Scroll:" +pos);
var div = document.getElementsByClassName('home');
if(pos>300){
let h = 90 + (pos/150);
let w = 80 + 1 +(pos/50);
if(h>100){
h = 100;
}
if(w>100){
w = 100;
}
h = " \" " + h + " %\"";
w = " \" " + w + " %\"";
console.log(h);
document.getElementsByClassName('home').height = Math.round(h);
document.getElementsByClassName('home').width = Math.round(w);
}
});
});
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
background-color: #CBCACA;
}
.wrapper{
height: 100%;
width: 100%;
position: relative;
}
.home{
height: 90%;
width: 80%;
position: fixed;
top: 5%;
left: 10%;
border-radius: 50px;
background-color: #302D2D;
}
.supply{
height: 100vh;
width: 70%;
position: relative;
left: 15%;
margin-top: 100%;
background-color: crimson;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Timo Roedler</title>
<meta name="description" content="small test with Scrolling">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrapper">
<div class="headline">
</div>
<div class="main">
<div class="home">
</div>
<div class="supply">
<div class="supply1">
</div>
<div class="supply2">
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="app.js"></script>
</body>
</html>