Skip to content

Commit ac381ef

Browse files
committed
added HTML 5 content
1 parent 79e154f commit ac381ef

30 files changed

+845
-2
lines changed

docs/_scripts/MyFirstHTML5Audio.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
3+
const MyFirstHTML5Audio = () => {
4+
return (
5+
<div>
6+
<h1>My First HTML5 Audio</h1>
7+
<audio controls>
8+
<source src="/audio/audio.mp3" type="audio/mp3" />
9+
Your browser does not support the audio tag.
10+
</audio>
11+
</div>
12+
);
13+
};
14+
15+
export default MyFirstHTML5Audio;

docs/_scripts/MyFirstHTML5Canvas.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, { useEffect } from 'react';
2+
3+
const MyFirstHTML5Canvas = () => {
4+
useEffect(() => {
5+
const canvas = document.getElementById('myCanvas');
6+
if (canvas) {
7+
const ctx = canvas.getContext('2d');
8+
ctx.fillStyle = 'lightblue';
9+
ctx.fillRect(0, 0, 200, 100);
10+
ctx.fillStyle = 'black';
11+
ctx.font = '20px Arial';
12+
ctx.fillText('Hello Canvas', 50, 50);
13+
}
14+
}, []);
15+
16+
return (
17+
<div>
18+
<h1>My First HTML5 Canvas</h1>
19+
<canvas id="myCanvas" width="200" height="100"></canvas>
20+
</div>
21+
);
22+
};
23+
24+
export default MyFirstHTML5Canvas;

docs/_scripts/MyFirstHTML5Form.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
3+
const MyFirstHTML5Form = () => {
4+
return (
5+
<div>
6+
<h1>Contact Us</h1>
7+
<form>
8+
<label htmlFor="name">Name:</label>
9+
<input type="text" id="name" name="name" required />
10+
11+
<label htmlFor="email">Email:</label>
12+
<input type="email" id="email" name="email" required />
13+
14+
<label htmlFor="phone">Phone:</label>
15+
<input type="tel" id="phone" name="phone" />
16+
17+
<label htmlFor="message">Message:</label>
18+
<textarea id="message" name="message" required></textarea>
19+
20+
<input type="submit" value="Submit" />
21+
</form>
22+
</div>
23+
);
24+
};
25+
26+
export default MyFirstHTML5Form;

docs/_scripts/MyFirstHTML5Page.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
3+
const MyFirstHTML5Page = () => {
4+
return (
5+
<div>
6+
<header>
7+
<h1>Welcome to My Website</h1>
8+
<nav>
9+
<ul>
10+
<li><a href="#">Home</a></li>
11+
<li><a href="#">About</a></li>
12+
<li><a href="#">Contact</a></li>
13+
</ul>
14+
</nav>
15+
</header>
16+
<main>
17+
<article>
18+
<h2>My First Blog Post</h2>
19+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
20+
</article>
21+
<section>
22+
<h2>About Me</h2>
23+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
24+
</section>
25+
<aside>
26+
<h3>Related Links</h3>
27+
<ul>
28+
<li><a href="#">Link 1</a></li>
29+
<li><a href="#">Link 2</a></li>
30+
<li><a href="#">Link 3</a></li>
31+
</ul>
32+
</aside>
33+
</main>
34+
<footer>
35+
<p>&copy; 2021 My Website. All rights reserved.</p>
36+
</footer>
37+
</div>
38+
);
39+
};
40+
41+
export default MyFirstHTML5Page;

docs/_scripts/MyFirstHTML5Video.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
3+
const MyFirstHTML5Video = () => {
4+
return (
5+
<div>
6+
<h1>My First HTML5 Video</h1>
7+
<video controls style={{ width: '100%' }}>
8+
<source src="/videos/video-1.mp4" type="video/mp4" />
9+
Your browser does not support the video tag.
10+
</video>
11+
</div>
12+
);
13+
};
14+
15+
export default MyFirstHTML5Video;
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { useState } from 'react';
2+
3+
const MyFirstHTML5WebStorageEx1 = () => {
4+
const [output, setOutput] = useState('');
5+
6+
const saveData = () => {
7+
localStorage.setItem('name', 'John Doe');
8+
localStorage.setItem('email', '[email protected]');
9+
};
10+
11+
const retrieveData = () => {
12+
const name = localStorage.getItem('name');
13+
const email = localStorage.getItem('email');
14+
setOutput(`Name: ${name}, Email: ${email}`);
15+
};
16+
17+
return (
18+
<div>
19+
<h1>My First Web Storage Example</h1>
20+
<button onClick={saveData}>Save Data</button>
21+
<button onClick={retrieveData}>Retrieve Data</button>
22+
<p>{output}</p>
23+
</div>
24+
);
25+
};
26+
27+
export default MyFirstHTML5WebStorageEx1;
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { useState } from 'react';
2+
3+
const MyFirstHTML5WebStorageEx2 = () => {
4+
const [output, setOutput] = useState('');
5+
6+
const saveData = () => {
7+
sessionStorage.setItem('name', 'Jane Doe');
8+
sessionStorage.setItem('email', '[email protected]');
9+
};
10+
11+
const retrieveData = () => {
12+
const name = sessionStorage.getItem('name');
13+
const email = sessionStorage.getItem('email');
14+
setOutput(`Name: ${name}, Email: ${email}`);
15+
};
16+
17+
return (
18+
<div>
19+
<h1>My First Web Storage Example</h1>
20+
<button onClick={saveData}>Save Data</button>
21+
<button onClick={retrieveData}>Retrieve Data</button>
22+
<p>{output}</p>
23+
</div>
24+
);
25+
};
26+
27+
export default MyFirstHTML5WebStorageEx2;
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { useState } from 'react';
2+
3+
const MyFirstHTML5WebStorageEx3 = () => {
4+
const [output, setOutput] = useState('');
5+
6+
const getLocation = () => {
7+
if (navigator.geolocation) {
8+
navigator.geolocation.getCurrentPosition(showPosition, showError);
9+
} else {
10+
setOutput('Geolocation is not supported by this browser.');
11+
}
12+
};
13+
14+
const showPosition = (position) => {
15+
const latitude = position.coords.latitude;
16+
const longitude = position.coords.longitude;
17+
setOutput(`Latitude: ${latitude}, Longitude: ${longitude}`);
18+
};
19+
20+
const showError = (error) => {
21+
setOutput(`Error: ${error.message}`);
22+
};
23+
24+
return (
25+
<div>
26+
<h1>My First Geolocation Example</h1>
27+
<button onClick={getLocation}>Get Location</button>
28+
<p>{output}</p>
29+
</div>
30+
);
31+
};
32+
33+
export default MyFirstHTML5WebStorageEx3;
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { useState } from 'react';
2+
3+
const MyFirstHTML5WebStorageEx4 = () => {
4+
const [location, setLocation] = useState(null);
5+
const [error, setError] = useState(null);
6+
const [watchId, setWatchId] = useState(null);
7+
8+
const startTracking = () => {
9+
if (navigator.geolocation) {
10+
const id = navigator.geolocation.watchPosition(
11+
(position) => showPosition(position),
12+
(error) => showError(error)
13+
);
14+
setWatchId(id);
15+
} else {
16+
setError('Geolocation is not supported by this browser.');
17+
}
18+
};
19+
20+
const stopTracking = () => {
21+
if (watchId) {
22+
navigator.geolocation.clearWatch(watchId);
23+
setWatchId(null);
24+
setLocation(null);
25+
setError(null);
26+
}
27+
};
28+
29+
const showPosition = (position) => {
30+
const { latitude, longitude } = position.coords;
31+
setLocation(`Latitude: ${latitude}, Longitude: ${longitude}`);
32+
};
33+
34+
const showError = (error) => {
35+
setError(`Error: ${error.message}`);
36+
};
37+
38+
return (
39+
<div>
40+
<h1>My First Geolocation Example</h1>
41+
<button onClick={startTracking}>Start Tracking</button>
42+
<button onClick={stopTracking}>Stop Tracking</button>
43+
<p>{location ? location : error}</p>
44+
</div>
45+
);
46+
};
47+
48+
export default MyFirstHTML5WebStorageEx4;

docs/html-5/_category_.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "👩🏻‍💻 HTML 5",
3+
"position": 5,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Learn the basics of HTML5 and how to create a simple webpage."
7+
}
8+
}

docs/html-5/graphics.mdx

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
import MyFirstHTML5Canvas from '../_scripts/MyFirstHTML5Canvas';
6+
7+
# 🙋🏻 HTML Graphics
8+
9+
HTML5 introduces new graphics elements and APIs that allow developers to create interactive graphics and animations directly in the browser. These elements and APIs provide powerful tools for creating visually rich and engaging web applications.
10+
11+
Some of the new graphics elements and APIs introduced in HTML5 include:
12+
13+
- **Canvas Element**: The `<canvas>` element is used to draw graphics, animations, and interactive content directly in the browser using JavaScript. It provides a drawing surface that can be manipulated with JavaScript to create custom graphics and animations.
14+
15+
- **SVG Element**: The `<svg>` element is used to embed scalable vector graphics (SVG) in a web page. SVG is a markup language for describing two-dimensional graphics and animations that can be scaled to any size without losing quality. The `<svg>` element provides a powerful tool for creating high-quality graphics and animations in web applications.
16+
17+
- **WebGL API**: The WebGL API is a JavaScript API for rendering 3D graphics in a web browser. It provides a low-level interface to the graphics hardware, allowing developers to create high-performance 3D graphics and animations directly in the browser.
18+
19+
By using these new graphics elements and APIs, you can create visually rich and interactive web applications that provide a more engaging user experience for your website visitors. These elements and APIs provide powerful tools for creating custom graphics, animations, and visual effects that enhance the look and feel of your web applications.
20+
21+
## Example
22+
23+
Here's an example of how you can use the `<canvas>` element to draw a simple graphic in an HTML document:
24+
25+
```html title="index.html"
26+
<!DOCTYPE html>
27+
<html>
28+
<head>
29+
<title>My First HTML5 Canvas</title>
30+
</head>
31+
<body>
32+
<h1>My First HTML5 Canvas</h1>
33+
<canvas id="myCanvas" width="200" height="100"></canvas>
34+
<script>
35+
const canvas = document.getElementById('myCanvas');
36+
if (canvas) {
37+
const ctx = canvas.getContext('2d');
38+
ctx.fillStyle = 'lightblue';
39+
ctx.fillRect(0, 0, 200, 100);
40+
ctx.fillStyle = 'black';
41+
ctx.font = '20px Arial';
42+
ctx.fillText('Hello Canvas', 50, 50);
43+
}
44+
</script>
45+
</body>
46+
</html>
47+
```
48+
49+
<BrowserWindow url="http://.../index.html">
50+
<MyFirstHTML5Canvas />
51+
</BrowserWindow>
52+
53+
In this example, we've used the `<canvas>` element to draw a simple graphic in an HTML document. We've created a canvas with a width of 200 pixels and a height of 100 pixels and used the `getContext('2d')` method to get a 2D drawing context for the canvas. We've then used the `fillRect()` and `fillText()` methods to draw a blue rectangle and text on the canvas.
54+
55+
By using the `<canvas>` element and JavaScript, you can create custom graphics and animations directly in the browser, making your web applications more visually engaging and interactive for your website visitors. The `<canvas>` element provides a powerful tool for creating dynamic and interactive graphics that enhance the user experience of your web applications.
56+
57+
## Conclusion
58+
59+
HTML5 introduces new graphics elements and APIs that provide powerful tools for creating custom graphics and animations directly in the browser. By using these elements and APIs, you can create visually rich and interactive web applications that provide a more engaging user experience for your website visitors. These elements and APIs allow you to create high-quality graphics, animations, and visual effects that enhance the look and feel of your web applications.

0 commit comments

Comments
 (0)