@@ -57,6 +57,8 @@ TBD. Will post an announcement when this is worked out.
|
||||
<li>Week 7 spring break</li>
|
||||
<li><a href="week-8-homework.html">Week 8 Homework (due on March 13th)</a></li>
|
||||
<li><a href="week-9-homework.html">Week 9 Homework (due on March 13th)</a> - walkthrough available <a href="week-9-walkthrough.html">here</a></li>
|
||||
<li>No week 10, 11, 12 homework</li>
|
||||
<li><a href="week-13-homework.html">Week 13 Homework</li>
|
||||
</ul>
|
||||
<h2>Lecture notes</h2>
|
||||
<p>
|
||||
@@ -73,6 +75,7 @@ I'll be posting these in advance of lectures, so you can review the material bef
|
||||
<li>Week 9: <a href="week-9-grid-2.html">Grid 2</a></li>
|
||||
<li>Week 11: <a href="week-11-flexbox-2.html">Flexbox 2</a></li>
|
||||
<li>Week 12: <a href="week-12-fonts.html">Fonts</a></li>
|
||||
<li>Week 13: <a href="week-13-hover.html">Hover</a>, <a href="week-13-transitions.html">Transitions</a></li>
|
||||
</ul>
|
||||
<h2>Generative AI policy</h2>
|
||||
<p>
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
[!]
|
||||
[=title "Week 13 Homework"]
|
||||
[=content-]
|
||||
<p>
|
||||
This week we're focusing entirely on <code>hover</code> and <code>transition</code>.
|
||||
Keep the lecture notes for both handy (<a href="week-13-hover.html">here</a> and <a href="week-13-transition.html">here</a>).
|
||||
</p>
|
||||
<p>
|
||||
Note that parts 3 and 4 are fairly difficult. Get started early!
|
||||
</p>
|
||||
<h1>Part 1: Ain't It Click?</h1>
|
||||
<p>
|
||||
Let's start by using a <code>span</code> to replicate
|
||||
the behavior of the <code>a</code> tag. <span class="goal">uses a span</span>.
|
||||
The end result shouldn't actually be clickable, but should have the same color and hover effect
|
||||
<span class="goal">has a hover effect that changes its color</span>.
|
||||
</p>
|
||||
<p>
|
||||
It's okay if you can't figure out exactly which colors an <code>a</code> tag switches between;
|
||||
<code>white</code> and <code>yellow</code> (the style I used for this website) is fine.
|
||||
Don't forget the underline! <span class="goal">visually identical to a link</span>
|
||||
(Hint: you may use any technique you wish as long as it's applied to a <code>span</code>,
|
||||
but this exercise is considerably easier if you have <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/text-decoration">text-decoration</a>).
|
||||
</p>
|
||||
<p>
|
||||
Make sure to use the <code>:hover</code> pseudo-class.
|
||||
</p>
|
||||
<h1>Part 2: Animate It!</h1>
|
||||
<p>
|
||||
Duplicate your replicated link (do NOT change the original!) and
|
||||
add <i>any</i> transition to it <span class="goal">a working transition</span> - it should be smooth and noticeable,
|
||||
and you should transition at least two properties <span class="goal">multiple properties animated</span>
|
||||
(e.g. both <code>color</code> and <code>background-color</code>). I recommend using
|
||||
this as an opportunity to play around with various transitions.
|
||||
</p>
|
||||
<h1>Part 3: Functions?</h1>
|
||||
<p>
|
||||
<i>This has a bit of math - if you have trouble with that part, please send me an email.</i>
|
||||
</p>
|
||||
<p>
|
||||
Transitions support a few different types of <i>timing function</i> - these are curves that
|
||||
describe how "fast" it moves between states. For instance, the default curve
|
||||
is an <i>S-shape</i> - it starts out slow, then speeds up around halfway through, then slows down again
|
||||
for the end. This timing function is called <code>ease</code>. It produces a very nice smooth animation that feels natural.
|
||||
</p>
|
||||
<p>
|
||||
But there are others! So, for this part, <b>practice researching on your own</b>
|
||||
to figure out,
|
||||
</p>
|
||||
<ul>
|
||||
<li>What curves exist and how they behave</li>
|
||||
<li>How to actually use them</li>
|
||||
</ul>
|
||||
<p>
|
||||
A good starting point is <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/transition">MDN</a>;
|
||||
you may also find some luck with <a href="https://www.w3schools.com/css/css3_transitions.asp">W3Schools</a>.
|
||||
</p>
|
||||
<p>
|
||||
Find at least three timing functions (besides the default <code>ease</code>) and
|
||||
demonstrate each of them with <code>background-color</code> and <code>:hover</code>. Make sure to clearly label them.
|
||||
(Read the lecture notes if this is confusing). <span class="goal">At least 3 timing functions, demonstrated properly</span>
|
||||
</p>
|
||||
<h1>Part 4: Bouncy Gallery</h1>
|
||||
<p>
|
||||
Use <code>:hover</code>, <code>transition</code>, and CSS Grid (make sure to read both Grid lecture notes if you're struggling with grid)
|
||||
to make a "bouncy gallery" of transitioned elements <span class="goal">hover, transition, and grid in use</span>.
|
||||
There should be 3 columns and at least 2 rows <span class="goal">3 columns, minimum 6 cells</span>. Explain each effect with text in its cell.
|
||||
</p>
|
||||
<p>
|
||||
The requirements for this one are loose - you don't have to include any specific combination of effects.
|
||||
However, it would be <i>passable</i> for each cell to contain just a span with an animated background-color
|
||||
using different transition <i>durations</i> and <i>timing functions</i>.
|
||||
<span class="goal">distinct transitions for each demonstration</span>.
|
||||
</p>
|
||||
<p>
|
||||
The goal of this is for you to experiment with new CSS properties. I highly recommend being creative with this one
|
||||
- you might hit on a design you really like for links or buttons on your website!
|
||||
</p>
|
||||
<h1>Extra Credit</h1>
|
||||
<p>
|
||||
For a whopping 15 points of extra credit, teach yourself about <code>box-shadow</code>
|
||||
and do a transitioned box-shadow on at least one of your Bouncy Gallery elements.
|
||||
</p>
|
||||
<p>
|
||||
Box-shadow is incredibly fun and worth learning - it adds a 3d "pop" to otherwise flat pages.
|
||||
</p>
|
||||
<h1>Self-Study</h1>
|
||||
<p>
|
||||
As if this homework didn't have enough research! To get ahead on the animations material,
|
||||
read about <a href="https://www.w3schools.com/css/css3_animations.asp">actual animations on W3Schools</a>
|
||||
- CSS exposes a <i>much</i> more powerful way to do animations; it's a lot more complicated than
|
||||
<code>transition</code>, but allows for some incredibly intricate behavior.
|
||||
</p>
|
||||
<h1>Submission</h1>
|
||||
<p>
|
||||
Don't forget to email me before the due date - April 10th.
|
||||
I need to get the email so I know when you finished and can view
|
||||
your website's git history from that date.
|
||||
</p>
|
||||
[/]
|
||||
[#template.html]
|
||||
@@ -0,0 +1,45 @@
|
||||
[!]
|
||||
[=title "Week 13: Hover"]
|
||||
[=content-]
|
||||
<p>
|
||||
So far we've gotten pretty good at making simple, functional websites - but, for the most part,
|
||||
they're <i>static</i>! This means they don't have any kind of interaction with the user;
|
||||
they may as well just be a printed page.
|
||||
</p>
|
||||
<p>
|
||||
This week, we're going to change that! Interactive webpages are a massive topic, but we're
|
||||
going to start with one of the simpler forms - the CSS <code>:hover</code> <i>pseudo-class</i>.
|
||||
</p>
|
||||
<p>
|
||||
The idea behind a <i>pseudo-class</i> is that it behaves like a normal CSS class,
|
||||
but is set <i>by the browser</i> under specific circumstances. This allows
|
||||
webpages to react to changes. The <code>:hover</code> pseudo-class is probably
|
||||
the most engaging one: when you select an element's hover pseudo-class,
|
||||
the rules will only be applied when that element is hovered by the mouse.
|
||||
</p>
|
||||
<p>
|
||||
For example, this code makes a simple hover button (assume the HTML is set up with some element which has <code>id="my_button"</code> set):
|
||||
</p>
|
||||
<pre><code>#my_button { /* this is *always* applied, no matter what */
|
||||
padding: 10px;
|
||||
background-color: purple;
|
||||
color: white;
|
||||
}
|
||||
#my_button:hover { /* these are only applied when the button is hovered, and override the previous ones */
|
||||
background-color: white; /* we say these are *more specific*, because of the :hover pseudo-class selector */
|
||||
color: purple;
|
||||
}</code></pre>
|
||||
<p>
|
||||
<style>#my_button1{ padding: 10px; background-color: purple; color: white; } #my_button1:hover {background-color: white; color: purple; }</style>
|
||||
The result looks like this: <span id="my_button1">My Button</span> (try putting your mouse over it!)
|
||||
</p>
|
||||
<p>
|
||||
The use for this is obvious! With <code>:hover</code>, you can produce a lot of
|
||||
really fun effects.
|
||||
</p>
|
||||
<p>
|
||||
Note that <code>:hover</code> can be applied to <i>any</i> selector, not just an ID selector!
|
||||
<code>.class_name:hover</code>, <code>body:hover</code>, and <code>div.button:hover</code>, are all valid selectors.
|
||||
</p>
|
||||
[/]
|
||||
[#template.html]
|
||||
@@ -0,0 +1,115 @@
|
||||
[!]
|
||||
[=title "Week 13: Transitions"]
|
||||
[=content-]
|
||||
<p>
|
||||
We can make simple static pages, and we can add color and style to them. With <code>:hover</code> (see <a href="week-13-hover.html">Week 13: Hover</a> if you haven't already!)
|
||||
we can make webpages that react <i>instantly</i> to changes.
|
||||
</p>
|
||||
<p>
|
||||
What if we want to react gradually? For instance, we might want a sidebar to expand slowly, or
|
||||
we might want a link to change color slowly instead of immediately. For this we use
|
||||
<code>transition</code>! Transition is a weird property in that it doesn't set anything
|
||||
itself - it <i>only</i> describes <i>how to transition between other properties</i>.
|
||||
</p>
|
||||
<p>
|
||||
This means <code>transition</code> is completely useless if we don't have any
|
||||
properties changing on our page. Fortunately, <code>:hover</code> <i>can</i>
|
||||
change properties, so we can animate <code>:hover</code> with a transition!
|
||||
</p>
|
||||
<p>
|
||||
The syntax looks like <code>transition: property duration;</code>, so for instance,
|
||||
<code>transition: background-color 1s;</code> literally means "take exactly 1 second
|
||||
to go from the old background color to the new one whenever it changes". Applying
|
||||
that to the example from the Hover article:
|
||||
</p>
|
||||
<pre><code>#my_button {
|
||||
padding: 10px;
|
||||
background-color: purple;
|
||||
color: white;
|
||||
transition: background-color 1s;
|
||||
}
|
||||
#my_button:hover {
|
||||
background-color: white;
|
||||
color: purple;
|
||||
}</code></pre>
|
||||
<p>
|
||||
<style>#my_button1{ padding: 10px; background-color: purple; color: white; transition: background-color 1s; } #my_button1:hover {background-color: white; color: purple; }</style>
|
||||
The result looks like this: <span id="my_button1">My Button</span>
|
||||
</p>
|
||||
<p>
|
||||
Try hovering it - it will take exactly 1 second for it to go from purple to white, and 1 second to go back!
|
||||
</p>
|
||||
<p>
|
||||
Note that the color still changes instantly - we never told CSS to transition the color,
|
||||
so it didn't. Transition supports comma-separated values like this:
|
||||
<code>transition: background-color 1s, color: 1s;</code>, so let's try that!
|
||||
</p>
|
||||
<pre><code>#my_button {
|
||||
padding: 10px;
|
||||
background-color: purple;
|
||||
color: white;
|
||||
transition: background-color 1s, color 1s;
|
||||
}
|
||||
#my_button:hover {
|
||||
background-color: white;
|
||||
color: purple;
|
||||
}</code></pre>
|
||||
<p>
|
||||
<style>#my_button2{ padding: 10px; background-color: purple; color: white; transition: background-color 1s, color 1s; } #my_button2:hover {background-color: white; color: purple; }</style>
|
||||
The result looks like this: <span id="my_button2">My Button</span>
|
||||
</p>
|
||||
<p>
|
||||
<i>Much</i> smoother.
|
||||
</p>
|
||||
<p>
|
||||
It bears note that not every property can <code>transition</code>! For instance,
|
||||
<code>font-family</code> can't be transitioned - what would that even do?
|
||||
We call this <i>animatable</i> - any property that is not <i>animatable</i>
|
||||
will not do anything in a transition (or animation - we'll get to animations later).
|
||||
A list of every property that can be transitioned is found <a href="https://www.w3schools.com/cssref/css_animatable.php">on W3Schools</a>.
|
||||
</p>
|
||||
<p>
|
||||
You can transition things that change the layout! CSS will <i>recompute</i> the layout for you. For instance,
|
||||
if I have,
|
||||
</p>
|
||||
<pre><code>#my_text_block {
|
||||
margin-left: 200px;
|
||||
margin-right: 200px;
|
||||
background-color: green;
|
||||
transition: margin 1s; /* note that this transitions margin-left and margin-right automatically -
|
||||
I could specify them separately, but that's a waste of time! */
|
||||
}
|
||||
#my_text_block:hover {
|
||||
margin-left: 0px;
|
||||
margin-right: 0px;
|
||||
}</code></pre>
|
||||
<style>
|
||||
#my_text_block {
|
||||
margin-left: 200px;
|
||||
margin-right: 200px;
|
||||
background-color: green;
|
||||
transition: margin 1s; /* note that this transitions margin-left and margin-right automatically -
|
||||
I could specify them separately, but that's a waste of time! */
|
||||
}
|
||||
#my_text_block:hover {
|
||||
margin-left: 0px;
|
||||
margin-right: 0px;
|
||||
}
|
||||
</style>
|
||||
<p>
|
||||
Then the result is something like,
|
||||
</p>
|
||||
<p id="my_text_block">
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus et volutpat nisi. Pellentesque id accumsan arcu. Nunc tempus, lorem ut venenatis blandit, quam orci pretium neque, ac bibendum nulla ex vel lectus. Curabitur viverra justo orci, eget porta erat ultrices a. In dictum ante nec quam semper ultrices. Pellentesque ac interdum tortor. Nam ultrices risus risus, vel vulputate turpis faucibus sed. Aenean eget urna vulputate, vulputate tortor molestie, varius dui. Quisque id ipsum auctor, dapibus lacus eget, laoreet eros. Morbi dignissim velit sed ipsum viverra, egestas efficitur nisl pretium. Cras eu porta turpis.
|
||||
</p>
|
||||
<p>
|
||||
<i>Try hovering it - it'll expand out to the edges!</i>
|
||||
</p>
|
||||
<p>
|
||||
Transitions can also be used with transforms and positions! This is very fun; I'm not going to go through any examples,
|
||||
but I <i>highly</i> recommend playing with it. If you need to brush up on <code>transform</code>,
|
||||
check out <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/transform">MDN's bit on the topic</a>
|
||||
(an example transition for a simple 2-second animation would be <code>transition: transform 2s;</code>).
|
||||
</p>
|
||||
[/]
|
||||
[#template.html]
|
||||
Reference in New Issue
Block a user