add dyanmic example

main
Matt Kendrick 2 years ago
parent 38d29b3fb4
commit 9a5d95edb5
  1. 2
      README.md
  2. 47
      dynamic.html
  3. BIN
      images/lonelymountain.jpg
  4. BIN
      images/noimage.png
  5. BIN
      images/shire.png
  6. BIN
      images/theshire.jpg
  7. 41
      lib/book.js
  8. 4
      lib/style.css
  9. 3
      static.html

@ -1,3 +1,3 @@
# Storybook # Storybook
Small javascript app to demostrate objects and arrays. Small javascript app to demostrate HtmlDOM, arrays and objects.

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="lib/style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Overpass">
<script src="lib/book.js"></script>
<title>Storybook</title>
</head>
<body>
<div id="book">
<h2 id="title">{book.title}</h2>
<div id="page">
<img src="images/noimage.png" id="pageImage">
<div id="pageText">
{page.text}
</div>
</div>
<div id="buttons">
{page.buttons}
</div>
</div>
<script type="text/javascript">
// array of pages
pages = [];
// page 1
buttons = [];
buttons.push(new Button(1, "Visit Lonely Mountain"));
pages.push(new Page("images/theshire.jpg", "The Shire is a region of J. R. R. Tolkien's fictional Middle-earth, described in The Lord of the Rings and other works. The Shire is an inland area settled exclusively by hobbits, the Shire-folk, largely sheltered from the goings-on in the rest of Middle-earth. It is in the northwest of the continent, in the region of Eriador and the Kingdom of Arnor.", buttons));
// page 2
buttons = [];
buttons.push(new Button(0, "Visit The Shine"));
pages.push(new Page("images/lonelymountain.jpg", "Erebor stood hundreds of miles from the nearest mountain range. Tolkien's rendering of Thrór's map in The Hobbit shows it with six ridges stretching out from a central peak that was snowcapped well into spring. The whole mountain was perhaps ten miles in diameter; it contained an immense wealth of gold and jewels.", buttons));
book = new Book("The Hobbit Locations", pages);
book.displayPage(0);
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 656 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

@ -0,0 +1,41 @@
class Book {
constructor(title, pages) {
this.title = title;
this.pages = pages;
}
displayPage(pageIndex) {
var page = this.pages[pageIndex];
document.getElementById("title").innerHTML = this.title;
document.getElementById("pageImage").src = page.imageSRC;
document.getElementById("pageText").innerHTML = page.text;
var buttons = document.getElementById("buttons");
// clear buttons
buttons.innerHTML = "";
for(var button of page.buttons) {
const btn = document.createElement("button");
btn.append(document.createTextNode(button.text));
btn.setAttribute("onclick", "book.displayPage("+ button.pageIndex +")");
buttons.append(btn);
}
}
}
class Page {
constructor(imageSRC, text, butttons) {
this.imageSRC = imageSRC;
this.text = text;
this.buttons = buttons;
}
};
class Button {
constructor(pageIndex, text) {
this.pageIndex = pageIndex;
this.text = text;
}
}

@ -28,14 +28,14 @@ body {
color: white; color: white;
} }
#controls { #buttons {
float: right; float: right;
display: inline; display: inline;
width: 15%; width: 15%;
padding: 10px; padding: 10px;
} }
#controls button { #buttons button {
display: block; display: block;
width: 100%; width: 100%;
margin-top: 5px; margin-top: 5px;

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="lib/style.css"> <link rel="stylesheet" href="lib/style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Overpass"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Overpass">
<script src="lib/script.js" type="text/javascript"></script>
<title>Storybook</title> <title>Storybook</title>
</head> </head>
<body> <body>
@ -17,7 +18,7 @@
The Shire is a region of J. R. R. Tolkien's fictional Middle-earth, described in The Lord of the Rings and other works. The Shire is an inland area settled exclusively by hobbits, the Shire-folk, largely sheltered from the goings-on in the rest of Middle-earth. It is in the northwest of the continent, in the region of Eriador and the Kingdom of Arnor. The Shire is a region of J. R. R. Tolkien's fictional Middle-earth, described in The Lord of the Rings and other works. The Shire is an inland area settled exclusively by hobbits, the Shire-folk, largely sheltered from the goings-on in the rest of Middle-earth. It is in the northwest of the continent, in the region of Eriador and the Kingdom of Arnor.
</div> </div>
</div> </div>
<div id="controls"> <div id="buttons">
<button>Prev</button> <button>Prev</button>
<button>Next</button> <button>Next</button>
</div> </div>
Loading…
Cancel
Save

Powered by TurnKey Linux.