In: Computer Science
Part 1; a simple slide show: Create a Web document called l5p1.html that displays one of the images from lab 2 in approximately the center of the page; centering need not be exact. Below the image, place three button elements labeled with the names of items from lab 2. (One of them must be the name of the item you chose to display.) Pressing a button should change the displayed image to that of the item named on the button. (Hint: There are at least two ways to do this that are discussed in the book. Think about the zIndex: and the visibility: property.) You may use any of these approaches, but please think about all of them. Create a link to this document from your index page.
In no more than a couple of paragraphs, explain which of the possible techniques you chose and why you chose it. Place your write-up below the buttons, on the same page.
Part 2; slide show as sequence: Create a new document, l5p2.html by copying the document from Part 1 and change it so that there's only one button labelled "Next". Each time the button is pressed, the next image must replace the current one. Pressing the button while the last image is displayed should return the display to the first image and start the cycle over. (Hint: You already have 90% of this done when you have completed Part 1; do not make this hard. Your want to count 0, 1, 2, 0, 1, 2, ... The modulus operator is your friend.) Create a link to this document from your index page.
Think of and describe at least two practical uses for displaying a sequence of images. Write no more than three or four paragraphs in HTML. Place your write-up below the "Next" button.
Program screenshots:
Part a):
Sample output:
Code to be copied:
l5p1.html
<!--This script is used to create a slider-->
<!DOCTYPE html>
<!--Html tag-->
<html lang="en">
<head>
<meta charset="utf-8" />
<!--Title of the page-->
<title>Slide Show tools</title>
<!--Css-->
<style type="text/css">
img {
position: absolute;
z-index: -1;
}
button {
height: 30px;
width: 197px;
}
</style>
<!--javascript-->
<script>
//Create a fucntion to show the images
function showTool(imgId)
{
var a = "";
if (imgId == "img1")
{
//set the text content to the paragraph
a = "Saw used to cut the material and these Handsaws"
+ " have been around for thousands of years.\n"
+ "Egyptian hieroglyphics exist depicting ancient\n "
+ "woodworkers sawing boards into pieces.\n";
document.getElementById("sample").innerHTML = a;
}
//If the image id is img2
else if (imgId == "img2")
{
document.getElementById("img2").style.zIndex = -1;
//set the text content to the paragraph
a = "Pliers are made in various shapes and sizes and for many uses."
+ " Some are used for gripping something round like a pipe or rods."
+ " Some are used for twisting wires";
document.getElementById("sample").innerHTML = a;
}
else if (imgId == "img3")
{
document.getElementById("img3").style.zIndex = -1;
//set the text content to the paragraph
a = "Pitchfork is an agricultural tool with a long handle and tynes used "
+"to lift and pitch or throw loose material, such as hay, straw or leaves.";
document.getElementById("sample").innerHTML = a;
}
// Assign the z-index values
//to the images using the image id's
document.getElementById("img1").style.zIndex = -1;
document.getElementById("img2").style.zIndex = -1;
document.getElementById("img3").style.zIndex = -1;
document.getElementById(imgId).style.zIndex = 1;
}
</script>
</head>
<body>
<!--Create a div-->
<div style="position:absolute; margin-left:30%">
<!--Create image tags-->
<img src="saw.jpg" id="img1" width="600" height="400" />
<img src="pliers.jpg" width="600" height="400" id="img2" />
<img src="pitchfork.jpg" width="600" height="400" id="img3" />
</div>
<div style="position:absolute; margin-top:400px; margin-left:30%">
<!--Create buttons-->
<button onclick="showTool('img1')">SAW</button>
<button onclick="showTool('img2')">PLIERS</button>
<button onclick="showTool('img3')">PITCH FORK</button>
<br></br>
<p id="sample">These are the Sample tools used to cut the material click on the buttons</p>
</div>
</body>
</html>
part 2:
Sample output:
Code to be copied:
l5p2.html
<!--This script is used to create a slider-->
<!DOCTYPE html>
<!--Html tag-->
<html lang="en">
<head>
<meta charset="utf-8" />
<!--Title of the page-->
<title>Slide show</title>
<!--Css-->
<style type="text/css">
img {
position: absolute;
z-index: -1;
}
button {
height: 30px;
width: 600px;
position: absolute;
z-index: -1;
}
</style>
<!--javascript-->
<script>
//Create a fucntion to show the images
function showTool(imgId,btnId)
{
//create a variable to display the text
var a = "";
//If the image id is 1
if (imgId == "img1")
{
//set the text content to the paragraph
a = "Saw used to cut the material and these Handsaws"
+ " have been around for thousands of years.\n"
+ "Egyptian hieroglyphics exist depicting ancient\n"
+ "woodworkers sawing boards into pieces.\n";
document.getElementById("sample").innerHTML = a;
}
else if (imgId == "img2")
{
a = "Pliers are made in various shapes and sizes and for many uses."
+ " Some are used for gripping something round like a pipe or rods."
+ " Some are used for twisting wires.";
document.getElementById("sample").innerHTML = a;
}
else if (imgId == "img3")
{
//set the text content to the paragraph
a = "Pitchfork is an agricultural tool with a long handle and tynes used "
+ "to lift and pitch or throw loose material, such as hay, straw or leaves.";
document.getElementById("sample").innerHTML = a;
}
// Assign the z-index values to the images using the image id's
document.getElementById("img1").style.zIndex = -1;
document.getElementById("img2").style.zIndex = -1;
document.getElementById("img3").style.zIndex = -1;
document.getElementById(imgId).style.zIndex = 1;
// Assign the z-index values to the buttons using the button id's
document.getElementById("btn1").style.zIndex = -1;
document.getElementById("btn2").style.zIndex = -1;
document.getElementById("btn3").style.zIndex = -1;
document.getElementById(btnId).style.zIndex = 1;
}
</script>
</head>
<body>
<!--Create a div for images-->
<div style="position:absolute; margin-left:30%">
<!--Create image tags-->
<img src="saw.jpg" id="img1" width="600" height="400" />
<img src="pliers.jpg" width="600" height="400" id="img2" />
<img src="pitchfork.jpg" width="600" height="400" id="img3" />
</div>
<!--Create a div for button and paragraph-->
<div style="position:absolute; margin-top:400px; margin-left:30%">
<!--Create buttons-->
<button onclick="showTool('img2', 'btn2')" id="btn1">Next</button>
<button onclick="showTool('img3', 'btn3')" id="btn2">Next</button>
<button onclick="showTool('img1', 'btn1')" id="btn3">Next</button>
<br>
<p id="sample" align="center">These are the tools used to cut the material</p>
</div>
</body>
</html>