New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

Set a Marquee to Autoplay with jQuery and Dreamweaver
Illustration by

Overcoming autoplay conflict errors in Google Chrome


From:

Set a Marquee to Autoplay with jQuery and Dreamweaver

with Chris Converse

Video: Overcoming autoplay conflict errors in Google Chrome

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.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
Set a Marquee to Autoplay with jQuery and Dreamweaver
38m 22s Intermediate Jun 21, 2011

Viewers: in countries Watching now:

This course, which builds on the foundations of Create an Interactive Homepage Marquee with jQuery and Dreamweaver, enhances the marquee with an auto-play feature that automatically advances through the slide images when the page is loaded. Working in a Dreamweaver environment, Chris Converse shows how to add auto play using a combination of HTML, CSS, and JavaScript, plus the implementation of hover states in jQuery. This course also covers adding play/pause functionality, as well as an interaction timeout, which will restart the marquee after a specified period of idle time.

Topics include:
  • Previewing a project across browsers and devices
  • Updating CSS and HTML in Dreamweaver
  • Adding debugging code
  • Declaring variables in JavaScript
  • Using setInterval
  • Stopping auto play during user interaction
Subjects:
Web Web Design Projects
Software:
Dreamweaver jQuery
Author:
Chris Converse

Overcoming autoplay conflict errors in Google Chrome

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.

Find answers to the most frequently asked questions about Set a Marquee to Autoplay with jQuery and Dreamweaver.


Expand all | Collapse all
please wait ...
Q: This course was updated in April, 2013. What changed?
A: Since the release of this course, Chrome conflicts with jQuery 1.6, and browsers run the autoplay when the windows is not in focus. To remedy these issues, the author has added a movie to Chapter 5 that will show you how to:
- Update the version of jQuery
- Detect the focus state of a web window
- Create a compound conditional JavaScript statement
 
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.
Upgrade now


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 Upgrade now

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 Set a Marquee to Autoplay 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

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.