tools = require('../js/tools'); tools.init()transitions¶
properties can change over time
either on events (e.g. a hyperlink, when you hover on it, or click it)
or programmatically (typically through JavaScript)
the browser has the ability to perform those changes smoothly
over a certain duration
in a continuous way
of course this applies to some properties only, e.g. lengths or colors
anything that can be mapped to a continuous space, so that one can do interpolation, between the beginning and ending states
transition example 1¶
how transitions work¶
you need to define a
transitionproperty on the elemente.g. the
<section>element hastransition: all 0.4s ease-in-outthen its
background-colorproperty changes somehow
here due to thesection:hoverselectorthe transition is requested to apply to
allproperties
so here it triggers to implement the color changeand the
ease-in-outalgorithm is used
over a0.4sduration
the transition property¶
is a shorthand property for setting in one rule
transition-property: comma separated names of properties
here we could/should have usedbackground-colorinstead ofalltransition-durationtransition-timing-functiontransition-delaythat we leave unchanged here (i.e. 0s)
most common timing functions¶
linearis, well of course, linear interpolationthe other 3:
ease-in,ease-out, andease-in-outmake the move smoother at one or two ends of the duration rangesee a more detailed explanation from the see also section below
transition example 2¶
do not overuse !¶
as a piece of advice
transitions can make user experience very nice
but do not overuse them
too many moving pieces quickly become more confusing than helpful
also notice that this starts to have to do with responsiveness
that deals with defining layouts that cope with geometry changes
that we will cover later on
here for example we have used
flex(more on this later)
transition example 3 (advanced)¶
transitions apply to all changes, not only triggered by a user
here we use JavaScript (studied later) to alter a <div>'s size
with e.g. growing.style.width = '200px'
animations¶
there is also a notion of animations in CSS
simply put, an animation allows to define a succession of states
each state being a collection of CSS properties
together with the point in time where they should apply
for example :
at the beginning of the duration (0%) background-color is red and color is blue
somewhere in the middle, say at (25%) of the duration, they become green and yellow
then at the end of the period (100%) they become black and white
more on animations¶
see one example on codepen for a better idea of what can be achived
extracted from this blog on CSS-Tricks
that is left to the interested reader as an exerciseWARNING like with transitions, and fun as they are,
these techniques should be used with extreme circumspection
see also¶
an explanation, among other things,
aboutlinear,ease-in,ease-out, andease-in-out