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

Set a Marquee to Autoplay with jQuery and Dreamweaver

Declaring global variables in JavaScript


From:

Set a Marquee to Autoplay with jQuery and Dreamweaver

with Chris Converse

Video: Declaring global variables in JavaScript

Now that we're ready to modify the JavaScript file from the previous course, let's open up the marquee.js in Dreamweaver or switch over to that open tab. And before the (document).ready in this particular script, where we actually setup the marquee, let's hit a few Returns and let's set up the five variables that we need to access to make the autoplay function properly. So this is the global area inside of the JavaScript. We're going to start by typing var for variable. I'm going to start by typing currentPanel. We're going to set this equal to 1.

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

Declaring global variables in JavaScript

Now that we're ready to modify the JavaScript file from the previous course, let's open up the marquee.js in Dreamweaver or switch over to that open tab. And before the (document).ready in this particular script, where we actually setup the marquee, let's hit a few Returns and let's set up the five variables that we need to access to make the autoplay function properly. So this is the global area inside of the JavaScript. We're going to start by typing var for variable. I'm going to start by typing currentPanel. We're going to set this equal to 1.

Next we're going to type variable totalPanels. We're going to set this equal to zero to start and then we'll have our jQuery actually generate the total number of panels by modifying the script below. Next we're going to set autoPlay. We're going to set this equal to True. Next we'll set timePassed. we'll set that equal to zero as well.

Next we'll type variable timeToChange. We're going to set this to 3. This is going to be three seconds, so that the marquee will play every three seconds. This will be too fast for our end project, but we wanted to set something quick while we're testing and debugging this so we can actually make sure that it plays properly and it doesn't take a lot of time to play through. Now inside of the (document).ready, we want to set up a few statements here that will send these variables over to the HTML page. These are going to be part of our debugging scripts. So I'm going to type a forward slash and an asterisk, type debug and then asterisk and forward slash. This is going to put a small comment in the beginning of this line.

And I'm going to put this debug comment before every time we send data over to the HTML, so that we can go back later and be able to remove these. So I'm going to start by typing a dollar sign, beginning and ending parenthesis. Inside of the parentheses we'll type two tick marks. I'm going to type autoPlay and this is the autoPlay class from the debug area in the HTML, not the variable that we have set up above here.

So we're going to set the autoPlay div, html, beginning and ending parentheses, semicolon, and then inside of the html we're going to put two ticks for a string literal, and then we're going to type autoPlay, which is just text, equals, space, and then I get the cursor outside of the tick mark, but before the ending parentheses, hit a plus sign, and now we need to access the global variables inside of this JavaScript. We are running inside of the function here, so in order to go out and get that global variable we're going to type window.autoPlay.

Again, by typing window here we can go out to the global script area. Now that we have the first debug statement set up, let's copy this. Command+C or Ctrl+C to copy. We're going to paste two, three more of these to give ourselves a total of four. We have five of them up here, but we're going to set the total panels a little bit later. So now Dreamweaver gives us a really nice way to select variable names and class names and element names. I'm going to come up here. I want to set the timePassed variable, it being the second one.

So I can come up here, double- click on timePassed, and then it will automatically select that item. Command+C or Ctrl+C to copy. Let's come down in the debug line here. Double-click on autoPlay. It will automatically highlight. I can hit Paste. I can double-click autoPlay here which is a string literal, and double-click autoPlay here which is a JavaScript variable. So this gives me again a really quick way to cut and paste the different values. Next, let's come up here and double-click timeToChange. Copy that. Let's paste that into the third spot and then let's come up and double-click currentPanel.

Let's come down and paste currentPanel on the fourth item here. At this point let's choose File > Save. So now at the beginning of the document we have our global five variables set up. We're going to set the state of these variables to debug in the HTML when we load the page. And in the next movie we're going to modify the existing script to get the total panels and the actual current panel based on the navigational item that was clicked.

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
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.

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
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



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.

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