Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding the jQuery hover statement

From: Create Animated Rollovers with jQuery and Dreamweaver

Video: Adding the jQuery hover statement

Now before we start creating our animations for the captions we need to figure out exactly where we need to animate the captions to. So I'm going to bring up a sketch and on the sketch what we figured out is with our thumbnails being 200 pixels wide by 115 pixels tall, all we want to do is first figure out how tall each caption is, since some captions might only be in one line and some might be three or four lines. So what we want to do is take the amount of padding that we set on the captions, top and bottom which is 35 pixels, 20 and 15 and we're going to take 115 which is the total height of the thumbnail, subtract 35 which is going to give us 80.

Adding the jQuery hover statement

Now before we start creating our animations for the captions we need to figure out exactly where we need to animate the captions to. So I'm going to bring up a sketch and on the sketch what we figured out is with our thumbnails being 200 pixels wide by 115 pixels tall, all we want to do is first figure out how tall each caption is, since some captions might only be in one line and some might be three or four lines. So what we want to do is take the amount of padding that we set on the captions, top and bottom which is 35 pixels, 20 and 15 and we're going to take 115 which is the total height of the thumbnail, subtract 35 which is going to give us 80.

Then we're going to add five additional pixels so that the bottom has five pixels of padding, and what we're going to do is take that number which is now 85 and subtract the height of whatever the height of the caption is. Then what we're going to do is use that value to animate to our new top position. So let's come back out into Dreamweaver, we're going to come over to the video_gallery related file, let's click on Code view, inside of jQuery's document ready we're going to come in here, I'm going to add a few lines and we're going to start by typing a dollar sign, beginning and ending parentheses, two tick marks inside for string literal, a.videoLink, outside of the parentheses we're going to type .hover beginning and ending parentheses then a semicolon.

So what this hover function does is it actually invokes any of the instructions inside of this function if our mouse hovers over any anchor tag with a videoLink class. Now what we're going to do inside of hover, let's split this open and we're going to define two functions. First, let's type function(), then a Return, then we're going to type function again, parentheses, brackets, and I'll remove the space.

So inside of the hover function what happens is the first function happens when the mouse rolls into the object, the second function happens when the mouse rolls outside of the area. So those two different functions that happen when we invoke the hover function inside of jQuery. So inside of the first function, inside of those brackets let's split that open, so inside of the first function what we want to do in here is create the two variables that we're going to set the position of that new caption based on the map that we just looked out inside of the sketch. I'm going to start by typing var captionPosition = 85-$(this) which refers back to the actual anchor link with the video class that we rolled over.

So (this).children, we want to search for all of the children inside of the anchor tag that we just rolled over, beginning and ending parentheses, inside of the parentheses two tick marks for the string literal, .caption, outside of the parentheses .height();. So the new height, the new captionPosition is going to be 85 minus whatever the height of the child inside of the anchor link we rolled over and we're going to get the height value of that object.

Let's hit Return, we're going to set a second variable, var iconPosition = captionPosition - 32. So if you remember from the introduction video we had the icon always just overlapping the very top of the caption. So whatever the caption height is going to be we're going to take our 50x50 pixel icon and shift it upwards -32 pixels, which is going to give us an 18 pixel overlap on the very bottom of the Play icon, regardless of how high the caption animates up and down.

At this point, let's go to the File menu, choose Save All and in the next movie we'll create the animations based on these variable values.

Show transcript

This video is part of

Image for Create Animated Rollovers with jQuery and Dreamweaver
 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Create Animated Rollovers with jQuery and Dreamweaver.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.