Jump to content
Search Community

Draggable & ThrowPropsPlugin - Container 100% Height...

rickideeuk test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi There

Ive just signed up to Greensock and so far I'm very impressed  :-P


I've got a couple of questions that hopefully you can help me with...


I've set up a codepen to show you, with 3 different sized boxes...

See the Pen oshwG by rickideeuk (@rickideeuk) on CodePen


1. Is there a way to make the container 100% height of whatever screen you're viewing the site on? - I've got it to be 100% of the width, but can't seem to make it 100% height?


2. Why on your demo versions have you set a width and height for the .box in the stylesheet, when the actual size of the .box seems to be controlled by 'TweenLite'.


3. Finally is there a way to alter the size of the .box depending on the screen resolution?

e.g. the .box is 500px wide if the screen res is 1000px or above. But changes to 250px wide if the screen is 999px or below???


Many Thanks

Link to comment
Share on other sites

Welcome to the forums. These questions are just about CSS really, and only tangentially related to GSAP, but here goes:


1. If you need 100% height of the window, you need to give the page itself 100% height first, since percentage based height can only be inherited from elements with non-automatic height (well tables are a different story but thats not what you're asking). Add this to your CSS and it should start working:

html, body {
  height: 100%;

2. Probably so the page has some styles before javascript loads, but I'm not the author =(


3. You'll want to look into media queries. Here's the first article I found. It looks something like this:

.element {
  width: 500px;
@media all and (max-width: 999px) {
  .element {
    width: 250px; // overrides when window width < 1000px
  • Like 3
Link to comment
Share on other sites

Hello rickideeuk, and Welcome to the GreenSock Forum!


Jamie beat me to it... so to add to Jamie's Great advice, I forgot about media queries:


Question #1:

You could just get the height of the browser window:

gridHeight = $(window).height();

Modified Example:

See the Pen GsErz by jonathan (@jonathan) on CodePen


Question 2:


Its always best to define the CSS (width, height, etc.. ) of the element your animating, so you have the defualt values to start from. Or you can use GSAP set() method to set the CSS properties before you start animating them.


Question 3:


For that type of behavior you would have to setup a resize() event that will listen if the browser is  resized. Then based on the different browser size or width, you could do different  things.


Helpful links on resize() event:





// resize event using on() method
$( window ).on("resize", function() {
      // resize code goes here

// resize event using the shortcut resize event
$( window ).resize(function() {
      // resize code goes here

// native javascript resize event
window.onresize = function(){
      // resize code goes here

Does that help? :)

  • Like 2
Link to comment
Share on other sites

Hi Jamie and Jonathan


Thanks for your help, it's now working just how I want it  8-)


I'm embarrassed about Question 1 though. I know CSS well, but got too caught up in the idea that it was script for the container that was the problem to realise I'd missed html out of my CSS!!!


Thanks again

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...