Codepen
http://codepen.io/tconroy/pen/RPzxgz
Basic setup:
I am trying to create a page structured with 2 columns inside of a centered container, max 1600px wide.
The left column contains the page content. The right column contains an ad unit (say, 640x480 px wide).
At 768px or lower media breakpoint, the 2 columns should stack ( so that the content is on top, and the ad is below it ).
The problem
When the page loads, there should be a 400x400px canvas element containing a white circle in the center of the screen (absolute center -- vertical and horizontal).
The Circle animates to a position directly behind the left column content.
After this, the circle should "expand" to fill the entire user's viewport, without covering the content or causing scrollbars to appear.
As shown in my below fiddle, I have gotten the initial circle / movement animation to work, however I am running into issues trying to figure out the expand portion. I need the circle to appear to grow/expand until it covers the entire viewport, but all text content / ad unit should not be obscured and no scrollbars should appear as a result of the animation.
I'm incredibly unfamiliar with canvas, so if anyone could give me a hand with without breaking the initial animation this it would be much appreciated. :)
http://codepen.io/tconroy/pen/RPzxgz
HTML:
<div class="container">
<div class="navigation row">
<h1 style="float:right;"><a href="#">Continue</a></h1>
</div>
<div class="content row">
<div class="circle-wrap">
<canvas class="circle" width="400" height="400"></canvas>
<div class="template-output">
<h1 class="title">
<span class="upper">Title TopLine</span>
<span class="lower">Title Bottom</span>
</h1>
<div class="body">
<p class="description">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolorum distinctio nesciunt nostrum magni neque. Iusto et delectus iure distinctio cupiditate, a sint doloremque ratione saepe sunt quisquam assumenda, eaque velit?</p>
<p class="byline">- Author Name</p>
</div>
</div>
</div>
</div>
<div class="ads row">
<figure class="ad">
<figcaption>Advertisement</figcaption>
<div id="welcome"></div>
</figure>
</div>
</div>
</div>
CSS:
/* BASE STYLES */
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html, body {
width: 100%;
height: 100%;
background: gray;
overflow: hidden;
}
/* END BASE STYLES */
/* LAYOUT */
.container {
width: 100%;
height: 100%;
max-width: 1600px;
margin: 0 auto;
outline: 1px solid black;
}
.row {
width: 50%;
height: 100%;
float: left;
display: block;
}
.row.content {
border: 1px solid blue;
}
.row.ads {
border: 1px solid red;
}
.row.navigation {
width: 100%;
height: auto;
}
@media screen and (max-width: 768px) {
.row {
width: 100%;
height: auto;
}
}
/* END LAYOUT STYLES */
/* ADVERTISEMENT */
.ad {
display: table;
margin: 0 auto;
}
.ad figcaption {
text-align: center;
margin: 0 auto;
}
.ad #welcome {
outline: 1px solid black;
background: darkgray;
width: 640px;
height: 480px;
margin: 0 auto;
}
/* END ADVERTISEMENT STYLES */
/* CONTENT */
.content {
min-height: 400px;
}
.content .template-output {
width: 400px;
position: relative;
}
.content .template-output .title {
font-size: 4em;
}
.content .template-output .title span {
display: block;
text-transform: uppercase;
}
.content .template-output .title .upper {
text-align: left;
}
.content .template-output .title .lower {
text-align: right;
}
.content .template-output .body {
position: relative;
}
.content .circle-wrap {
position: relative;
width: 100%;
height: 100%;
margin: 0 auto;
}
.content .circle-wrap .circle {
width: 400px;
height: 400px;
outline: 1px solid black;
position: absolute;
left: 0;
top: 0;
transform: translate(0%, 0%);
}
.content .circle-2 {
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
/* END CONTENT STYLES */
JAVASCRIPT (included: jQuery and GSAP TweenMax libraries)
/*
I have successfully created the canvas element in the center
of the screen and animate it to the left column. Now, I want the circle to "expand" behind the content, and fill the entire viewport.
It should not cause scrollbars to appear or cover the text content.
*/
(function () {
var tl = new TimelineMax();
var $canvas = $('.circle'),
$canvas_wrap = $('.circle-wrap'),
canvas = $canvas[0],
context = canvas.getContext('2d'),
canvas_width = canvas.width,
canvas_height = canvas.height;
context.globalCompositeOperation='destination-over';
draw(context);
/* TIMELINE STUFF */
var canvas_opts = {
'center-to-destination': {
xPercent: -50,
yPercent: -50,
top: '50%',
left: '100%',
delay: 1.5
}
};
tl.from(canvas, 1, canvas_opts['center-to-destination']);
})();
canvas
object to stretch and cover the entire viewport or do you want the innercircle
that you have drawn to do that? two different things imho. also, whichever of these two objects you choose to animate, setting them behind all of the content would mean playing with thez-index
CSS property of not just thecanvas
object, but also the other objects that are supposed to appear on top of it. I think your HTML structure will need to change a lot for that. I could be wrong of course. – Oeuvre200
forcurrX
is basically dependant oncurrRadius
. Whatever amount you initially animatecurrRadius
with, you have to provide the same amount to the nextcurrX
animation. – Oeuvreleft
animation. Can you tell me a example scenario where it behave differently? Please edit the codepen demo in order to demonstrate if you need to. – Oeuvre