<aside> <img src="/icons/list_purple.svg" alt="/icons/list_purple.svg" width="40px" />

By the end of this worksheet, you will be able to:

.stop()

Before getting into today’s topics, let’s introduce a useful jQuery action: .stop()

The .stop() action in jQuery is used to stop animations that are currently running (or pending) on elements. There are situations where animations can be triggered multiple times (like on repeated hover events), which can cause animations to queue up (especially noticeable if the event occurs before the animation completes). .stop() helps by halting the current or queued animations so new ones can run immediately.

Here’s how it’s used:

$('#box').mouseenter(function() {
	$(this).stop().animate({ width: '400px' }, 500);
})

$('#box').mouseleave(function() {
	$(this).stop().animate({ width: '200px' }, 500);
});

Have a look at this example on Codepen to see it in action:

Mouse your mouse on and off each box a few times. Notice how the animations stack up into a queue on the first box, but not the second?

Mouse your mouse on and off each box a few times. Notice how the animations stack up into a queue on the first box, but not the second?

Without .stop(), if you quickly move your mouse in and out of the box, the animations will stack up, causing an ongoing queue of animations to complete. With .stop(), it cancels the current animation queue before starting the new one.

<aside> <img src="/icons/code_lightgray.svg" alt="/icons/code_lightgray.svg" width="40px" />

.stop() is only for jQuery animations, like .animate() or .fadeIn() — it won’t affect CSS transitions or JavaScript-based animations outside jQuery.

</aside>

Cool? Let’s begin.


Introduction

This week we’re going to learn two things: First, how to integrate Google fonts into Web sites. Second, how to use a jQuery function called .scrollTop() to smoothly scroll the page to a particular location.

Google Fonts

For the most of the history of Web design, only a few ‘standard’ fonts have been available. A ‘standard’ font is essentially a font that designers could rely on being installed on the user’s computer. If you used a font that wasn’t commonly found on most computers, then the browser would display text using its default font, which was usually Times.