2

I've been trying to figure out how this website made the following effect and I can't find the answer.

https://www.dezeynne.com/

It seems that while resizing the browser window, the main div resized also with it dynamically by changing the height.

I'm also bad in Math, so please help me to understand the idea behind this awesome effect. It would be also nice to help me figure out how the parallax is working, I mean how can I change the position of the background in css/javascript while resizing the browser window.

$(document).ready(function() {
   var $window = $(window);
   var $welcomeElement = $(".welcome");
   var defaultHeight = $welcomeElement
   console.log($welcomeElement);
   $window.resize(function() {
      // I'm stuck here at math as you see
      $welcomeElement.css("height", ($window.width() - $window.height()) - 
      $welcomeElement.innerHeight());
      console.log("Resized!");
      console.log($window.height());
   });
});
1
  • Learn about CSS Media Queries Commented Aug 15, 2017 at 19:51

1 Answer 1

1

Have you considered using viewport units?

Set the div to height:50vw;

#main {
background:#daa;
height:50vw;
color:#400;
font-size:10vw;
text-align:center;
line-height:50vw;
}
<div id="main">Hello</div

Sign up to request clarification or add additional context in comments.

3 Comments

It works! but how can do this with javascript? and how can handle the paralax effect? Any idea would be helpful
Multiply the window's width with a ratio like maybe 0.5 and don't forget to add the unit, like +"px". The paralax effect could be done using background-position
ok thank you for your help. I'mark the question as solved and will be in touch if I have questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.