CIS166AA - JavaScript Glendale Community College
6000 West Olive Avenue
Glendale, AZ 85302 623.845.3000
   

 
   
 

 


 

 

 
Lesson 04
 
Lesson 4 - Reading

REQUIRED:

  • Read and do the practice work in Chapter 4 and Chapter 5
Lesson 4 - Notes and Practice Work

 

Working with Images

Simple Rollover Images

This method insures that the images are preloaded so that there is no delay in displaying the image when the events occur.

<html>
<script>

imageA = new Image
imageB = new Image

imageA.src = "planes.jpg"
imageB.src = "car.jpg"

</script>
<body>

<a href="#"
onMouseOver="document.myimage.src=imageB.src"
onMouseOut="document.myimage.src=imageA.src">
<img src="planes.jpg" name="myimage" border="0" >
</a>

</body>
</html>

Example

Multiple Links one Simple Rollover Image

Each link points back to the document, which is fine because just need something to click. The object "myimage" then is allowed to rollover each image based which link is clicked.

<html>
<script>

imageA = new Image
imageB = new Image
imageC = new Image
imageD = new Image

imageA.src = "planes.jpg"
imageB.src = "car.jpg"
imageC.src = "rock.jpg"
imageD.src = "leaves.jpg"

</script>

<body>

<img src="planes.jpg" name="myimage" align="left">

<a href="#" onClick="document.myimage.src=imageA.src">Planes</a><br>
<a href="#" onClick="document.myimage.src=imageB.src">Car</a><br>
<a href="#" onClick="document.myimage.src=imageC.src">Rock</a><br>
<a href="#" onClick="document.myimage.src=imageD.src">Leaves</a><br>

</body>
</html>

Using a Function to Create a Simple Rollover Image

The function "swapimg" takes the two arguments: A and B. These are then used to define the .src of the myimage object.

<html>
<script>

imageA = new Image
imageB = new Image
imageC = new Image
imageD = new Image

imageA.src = "planes.jpg"
imageB.src = "car.jpg"
imageC.src = "rock.jpg"
imageD.src = "leaves.jpg"

function swapimg(a, b)
{
a.src = b.src
}
</script>

<body>

<img src="planes.jpg" name="myimage" align="left">

<a href="#" onMouseOver="swapimg(myimage,imageA)">Planes</a><br>
<a href="#" onMouseOver="swapimg(myimage,imageB)">Car</a><br>
<a href="#" onMouseOver="swapimg(myimage,imageC)">Rock</a><br>
<a href="#" onMouseOver="swapimg(myimage,imageD)">Leaves</a><br>

</body>
</html>

Example

Planes
Car
Rock
Leaves

Creating a rotating image

The following uses an array to store the images used and then recalls the function every 2 seconds to get the new image.

<html>
<script>

images = new Array("planes.jpg","car.jpg","rock.jpg","leaves.jpg")
icounter = 0
imgCount = images.length

function rotate()
{
icounter++

if(icounter == imgCount)
{
icounter = 0
}

myimage.src=images[icounter]
setTimeout("rotate()", 2000)
}

</script>

<body onLoad="rotate()">

<img src="leaves.jpg" name="myimage">


</body>
</html>

Example

MouseOver the image to start image rotation

 

Lesson 4 - Assignment

  1. Create a single HTML file that contains the following:

    • multiple image rollovers, using a single function
    • a slideshow
    • a cycling banner and/or image with a random start

  2. Save the file as CIS166AA04.HTM
  3. Upload the file and images used to your CIS166aa folder on Gecko.

Send in Your Assignment to be Graded

After you have read these instructions, click on the link "Submit my assignment for grading" below. This will create a message for you to use to send in your assignment to the CIS166AA grader. It already will have the message address and the subject line filled in. DO NOT CHANGE THE ADDRESS OR THE SUBJECT LINE. Enter the following required information as the message text:

  • your full name
  • your palette account username
    • If you do not know your palette username, use your student ID card at a palette account lookup station in HTC1 or HTC2. If you are off campus, call the Student Help Desk at 623.845.HELP (4357) or send an email message to student-helpdesk@student.gc.maricopa.edu to request your palette username.
  • you email address
  • course section number
  • Include the full URL to lesson 4
    ( ie. http://gecko.gc.maricopa.edu/~palette_username/cis166aa/cis166aa04.htm )

Only by following this process can you be guaranteed that your assignment will get graded and the score recorded correctly.

Submit my assignment for grading

 


  Back to Top