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

Calculating and animating between photos

From: Create an Interactive Homepage Marquee with jQuery and Dreamweaver

Video: Calculating and animating between photos

Now that we have all the variables set up based on the anchor link we clicked on, inside of our set up navigation links after the variable we have declared, let's hit a few line Returns and let's change the photo position. So, we'll start with a Dollar sign, beginning and ending parentheses, two tick marks, string literal, type 'marquee_photos'. We are going to target the marquee_photos div. Outside of the parentheses, type .animates.

Calculating and animating between photos

Now that we have all the variables set up based on the anchor link we clicked on, inside of our set up navigation links after the variable we have declared, let's hit a few line Returns and let's change the photo position. So, we'll start with a Dollar sign, beginning and ending parentheses, two tick marks, string literal, type 'marquee_photos'. We are going to target the marquee_photos div. Outside of the parentheses, type .animates.

This is jQuery's built-in function to animate the properties. Inside of animate, beginning and ending bracket, we are going to type 'left:', space. Then we are going to go get the variable newPhotoPosition, choose Command or Ctrl+C to copy that, Command or Ctrl+V to paste. So, basically, animate again, is jQeury's built-in function to animate CSS properties of HTML elements on the page.

So, it will take whatever the current position is and perform this animation function. Outside of the brackets, choose a comma, space, and then 1000. This is a time interval, so this is 1000 ticks, or 1 second in JavaScript. To test this, let's choose File > Save. Let's go back out. Let's hit Reload in our browser. Now, when I click each one of these dots, this will animate the photo div container holding the photographs.

The new photo position is calculated by taking the number of the navigation item. The first one being 0, 1, 2 and 3, multiplying it by 700, and then animating the new position of the CSS based on 700 times the index number of the item we clicked. So, this is working perfect. Let's go back to our JavaScript. That takes care with the photos. Now we want to handle the captions. Let's type a Dollar sign, beginning and ending parentheses, two tick marks, .marquee_caption.

We are going to set animate on this as well, beginning and ending parentheses, semicolon. Inside of the animate, let's get two brackets. Let's type 'top:'. This sets the top value of the CSS property, two tick marks for a string literal, 340px. This is the lowest point we want the caption to be. This shows us the top 10 pixels across the top.

Let's put a comma in here, space, 500. We want this to be half a second, so in the time it takes the photo to move one second across, we want to have the caption take half the amount of time to move down, change, and then move back up. So, over the course of one second, the photos will just do one movement; the captions will do. They will go down and up. So after 500, let's add a comma, type in 'function', beginning and ending parentheses, beginning and ending bracket.

This is going to be a callback, which is basically going to happen after the animation has triggered down to 340 pixels on the top over the course of 500 ticks. Let's split this. Let's come inside the marquee_caption. Let's create a new variable, newHTML equals, Dollar sign, beginning and ending parentheses. We are going to come up here and grab the newCaption because we said over here that this is the navClicked is going to get the marquee panel data bases on the actual index of the anchor tag that was clicked.

Type in newCaption, outside of newCaption.html, beginning and ending parentheses, semicolon. This is jQuery's built-in way to grab all of the HTML inside of this object. Next line, Dollar sign, beginning and ending parentheses, two tick marks, marquee_caption_content.html, beginning and ending parentheses, semicolon.

Inside of the marquee_caption_content, we are going to take all of the newHTML code that we got from the newCaption variable, paste it in there. And then lastly, we are going to run a custom function, setCaption, beginning and ending parentheses, and a semicolon. Now to setCaption function is something we haven't written yet. We are going to start that in the next movie. But basically, what we are going to do is once we set the newCaption information here, we are going to animate this down. We are going to have to perform some calculations to see how tall the newCaption is so that we know how to animate it back up, so that the entire caption fits on the screen, and again we will start that in the next movie.

Show transcript

This video is part of

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 an Interactive Homepage Marquee 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 preferences from 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.