Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
On the next line, let's start with dollar sign, beginning and ending parentheses, tick marks inside for a string literal .marquee_photos. Outside of the parentheses .animate, parentheses, semicolon. Inside of the parentheses, beginning and ending bracket. Inside of the brackets, left:. Let's double click newPhotoPosition variable name. Let's paste that after the colon.
Outside of the brackets but still inside of the parentheses, comma, space, 1000 milliseconds, comma, space, function for a callback function, parentheses, beginning and ending bracket. Let's split that open on the brackets. Now inside of the brackets, dollar sign, parentheses, tick marks for a string literal, marquee_photos, .css, beginning and ending parentheses, semicolon.
Inside of the parentheses, tick marks for a string literal, type left, outside of the string literal, comma, two tick marks again for a string literal, a minus sign, two plus signs, two tick marks for a string literal, px. Now inside the plus signs is where we need to calculate where we need the CSS to be set to make the second to the last photo which is the last photo in the marquee content. So to get that value, we need to multiply the photoWidth times the totalPanels. So let's start with the beginning and ending parentheses, since we want to have this calculated first, window.photoWidth. We are going to multiply that by window.totalPanels.
So multiplying the totalPanels by the photoWidth is going to give us the exact position of that fourth item, which is actually the fifth item in the lineup, since we manipulated the position of all the photographs. Now, the last thing we need to do is set what happens inside of this else statement. So what we are going to do here is we are going to come down to where we have the photo animation setting. So let's select this statement here that says $(' .marquee_photos').animate(left: newPhotoPosition. Let's cut that. Let's come up here, inside of the else statement, delete our alert, and let's put this action inside of here.
So in the case that we are not on the last panel going to the first or the first going to the last, then we are going to animate our normal state, or the general newPhotoPosition without redefining it, for either of the other two scenarios. So to test this, let's choose File > Save. Let's come out to our browser and hit Reload. Now to test this, we are on the first panel. Let's come over here and click the last panel. Now the photos will actually animate over to the right. Now let's click on the second panel here. Notice that the allusion here is that we continue to animate to the right, but what's eventually happened is once we animated to that last panel, we shifted the entire photo line to the left. So as we continue to animate counting backwards, the photos continue to move toward the right-hand side.
Let's go out to the last panel from the first panel. We get that same wraparound effect. We are on the last panel. Let's come back to the first panel and we get the wraparound effect of now the photography moving to the left. Now I am on the first panel. If I click the second one, the allusion again here is that the photo panel continues to move to the left, giving us the effect that we are continuing to move to the right, even though after the animation from the last panel to the first jumped all of the photos across so that we can continue to animate the same direction.
Now we have the wraparound effect working for both the last and first photos. In the next movie, we'll make an adjustment to the autoPlay so that when this plays automatically the autoPlay will also trigger the wraparound effect.
Get unlimited access to all courses for just $25/month.Become a member
58 Video lessons · 65452 Viewers
61 Video lessons · 96251 Viewers
56 Video lessons · 110030 Viewers
82 Video lessons · 105042 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.