Add files for assignment 01

This commit is contained in:
Manuel Thalmann 2024-03-01 18:07:26 +01:00
parent 51d9be7063
commit 187b450f85
10 changed files with 164 additions and 0 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -0,0 +1,37 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Navibar Demo</title>
<script src="navibar.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
navigation-bar {
width: 100vw;
position: fixed;
bottom: 0;
/* ... */
}
navigation-bar a img {
opacity: 0.3;
/* ... */
}
</style>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,26 @@
class CustomNavigationBar extends HTMLElement {
constructor() {
super()
const shadowRoot = this.attachShadow({mode: 'open'})
shadowRoot.innerHTML = `
<style>
div.navibar {
align-items: center;
background-color: #ccc;
margin: 0;
width: 100%;
height: 100%;
}
::slotted(a) {
display: block;
text-align: center;
}
</style>
<div class="navibar">
<slot></slot>
</div>`
}
}
customElements.define('navigation-bar', CustomNavigationBar)

View file

@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Progress Bar Demo</title>
<script src="progress.js"></script>
<script src="demo.js"></script>
</head>
<body>
<p>
<custom-progress-bar />
</p>
<p>
<custom-progress-bar value="25" />
</p>
<p>
<custom-progress-bar value="0" />
</p>
</body>
</html>

View file

@ -0,0 +1,17 @@
/*
* Progress Bar Demo
*/
window.onload = () => {
document.querySelector('p:nth-child(1) custom-progress-bar').progress = 75;
document.querySelector('p:nth-child(2) custom-progress-bar');
var pb = document.querySelector('p:nth-child(3) custom-progress-bar');
setInterval(() => changePb(pb), 20);
}
const changePb = (pb) => {
if (Math.random()>0.85) {
pb.progress = (parseInt(pb.progress)+1) % 101;
}
}

View file

@ -0,0 +1,59 @@
class CustomProgressBar extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({mode: 'open'});
shadowRoot.innerHTML = `
<style>
:host {
display: inline-block;
width: 5rem;
height: 1rem;
}
.progress {
display: inline-block;
position: relative;
border: solid 1px #000;
padding: 1px;
width: 100%;
height: 100%;
}
.progress > .bar {
background: #9cf;
height: 100%;
}
.progress > .label {
position: absolute;
top: 0;
left: 0;
width: 100%;
text-align: center;
font-size: 0.8rem;
line-height: 1.1rem;
}
</style>
<div class="progress" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
<div class="bar" style="width: 0px;"></div>
<div class="label">0%</div>
</div>
`;
this._progressElement = shadowRoot.querySelector('.progress');
this._label = shadowRoot.querySelector('.label');
this._bar = shadowRoot.querySelector('.bar');
}
static get observedAttributes() { return ['value']; }
attributeChangedCallback(name, oldValue, newValue, namespaceURI) {
if (name === 'value') {
const newPercentage = newValue === null ? 0 : parseInt(newValue);
this._progressElement.setAttribute('aria-valuenow', newPercentage);
this._label.textContent = newPercentage + '%';
this._bar.style.width = newPercentage + '%';
}
}
get progress() { return this.getAttribute('value'); }
set progress(newValue) { this.setAttribute('value', newValue); }
};
customElements.define('custom-progress-bar', CustomProgressBar);