Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this update to the homepage promotional marquee, we're going to be modifying two issues that have come up recently. One, some browsers will continue to run the setinterval when the web browsers in the background are obscured by another tab, or what's called not being in focus. And another issue is version 1.6 of jQuery, the animate function conflicts with a later version of Chrome, which will stop the autoplay from happening. So to fix these two issues we will be making some changes to the marquee course. So we're going to be doing inside of your final marquee project we're going to be taking index.html and marquee.js files and open them either in Dreamweaver or a code editor.
Now if you're following along in Dreamweaver, with both of these files open, make sure that the index.html file is showing in Code view. We're going to be making our changes in code. And for those following along in the text editor, again have both of these files open. So the first thing we're going to do is we're going to update the version of jQuery that we're using. So inside of Dreamweaver or your text editor, let's come down to the heading area of the HTML. Let's find where we're including jQuery 1.6. Let's come in here to the source. Let's delete this, and let's replace this with a reference to jQuery 1.8.
In this case I'm going to link right to the jquery.com site, so this is going to be code.jquery.com/jquery-1.8.3.min.js. Now with jQuery updated, let's hit Save. Let's come over to the marquee.js. Inside of here, at the top of the document, let's add one more variable. We'll type var window, focus will be the name of our variable. We'll set that equal to true.
Let's come down here and copy that name. Let's come down inside the document ready. What we're going to do here is detect the window focus, so we're going to do that by typing window.onfocus. We're going to set this equal to a function, beginning and ending parentheses, beginning and ending bracket. Inside the brackets let's paste our variable name. We'll set that equal to true and add a semicolon.
Next, let's grab this entire line. Let's copy it. Let's paste it on the next line. Let's change onfocus to onblur, and let's change the window focus variable to equal false. So now with our variable declared and the value changing based on the window focus or blur, next we'll come into our script, find the auto advance function name. Inside of here we have a conditional statement that checks to see whether the winded.autoplay variable equals true.
We're going to add a second conditional statement here, so inside the parentheses, hit a space type two ampersands, then a space, window.window focus==true. So now, not only are we testing the autoplay but we're also testing to see if the window is even in focus. With this change in place, hit File > Save. Make sure all of your files are saved, come back to the operating system, and let's opens up in a browser.
So in the browser here we can see our time past variable is being modified. When time past equals time to change the marquee will auto-advance. But now what I'm going to do is come over to the desktop. I'm going to activate the desktop, which will now put my web browser not in focus, and then watch the time past variable. We can see here that once this gets to six, which matches the time to change, the browser is not going to advance until we click on the browser, bring this to being in focus, and then once the time variables match, it's going to autoplay.
So now, with these two changes in place, the animation won't attempt to play when the browser focus is not true, and we can also be assured that the set interval is now going to work again in the latest versions of Chrome.
Get unlimited access to all courses for just $25/month.Become a member
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.
Your file was successfully uploaded.