Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sticky nav #684

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a2f9026
added funtionality and styling to drumkit
shb1383 May 16, 2024
1f98709
added functionality and styling to clock hands
shb1383 May 16, 2024
9ba8afe
created handle documents and function to update its properties
shb1383 May 20, 2024
9e61433
created various methods to sort given data
shb1383 May 21, 2024
a383123
added styling and toggle functions to panels
shb1383 May 22, 2024
314b55f
created fetch and functions to retieve data and display results for s…
shb1383 May 24, 2024
3aa1f51
created code using various array methods to complete tasks
shb1383 May 24, 2024
fc562b0
created and styled drawing function on canvas
shb1383 May 26, 2024
6a64ccd
coded various console tricks
shb1383 May 27, 2024
e307d73
created handle check function and applied event listener to it
shb1383 May 28, 2024
4e762e8
grabbed elements, created functions, and attached event listeners
shb1383 May 29, 2024
db3f228
created event listener on keys to detect secret code
shb1383 May 29, 2024
ec11536
grabbed image elements and created sliding function
shb1383 May 30, 2024
6661813
created copies
shb1383 Jun 5, 2024
edbcfb4
created functions to add, populate, and toggle
shb1383 Jun 8, 2024
5f81ef5
created mouse move shadow function
shb1383 Jun 9, 2024
f623d74
created function to sort without articles
shb1383 Jun 10, 2024
6ae3a81
added up times with reduce
shb1383 Jun 11, 2024
b6dfea8
created various functions for webcam
shb1383 Jun 11, 2024
716a343
implemented speech detection
shb1383 Jun 13, 2024
016b0f1
created function to access speed and postion watch accordingly
shb1383 Jun 14, 2024
ef4589a
created highlight link function
shb1383 Jun 15, 2024
5ca590b
created functions to populate and set voice plus function to toggle a…
shb1383 Jun 15, 2024
6329c50
created sticky nav function and applied it to css elements
shb1383 Jun 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 01 - JavaScript Drum Kit/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@
<audio data-key="76" src="sounds/tink.wav"></audio>

<script>
function removeTransition(e) {
if (e.propertyName !== 'transform') return;
e.target.classList.remove('playing');
}

function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
if (!audio) return;

key.classList.add('playing');
audio.currentTime = 0;
audio.play();
}

const keys = Array.from(document.querySelectorAll('.key'));
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener('keydown', playSound);
</script>


Expand Down
22 changes: 22 additions & 0 deletions 02 - JS and CSS Clock/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,35 @@
background: black;
position: absolute;
top: 50%;
transform-origin: 100%;
transform: rotate(90deg);
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
}

</style>

<script>
const secondHand = document.querySelector('.second-hand');
const minsHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand');

function setDate() {
const now = new Date();

const seconds = now.getSeconds();
const secondsDegrees = ((seconds / 60) * 360) + 90;
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;

const mins = now.getMinutes();
const minsDegrees = ((mins / 60) * 360) + ((seconds/60)*6) + 90;
minsHand.style.transform = `rotate(${minsDegrees}deg)`;

const hour = now.getHours();
const hourDegrees = ((hour / 12) * 360) + ((mins/60)*30) + 90;
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
}

setInterval(setDate, 1000);
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions 03 - CSS Variables/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">

<style>
:root {
--base: #ffc600;
--spacing: 10px;
--blur: 10px;
}

img {
padding: var(--spacing);
background: var(--base);
filter: blur(var(--blur));
}

.h1 {
color: var(--base);
}
/*
misc styles, nothing to do with CSS variables
*/
Expand All @@ -46,6 +60,15 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
</style>

<script>
const inputs = document.querySelectorAll('.controls input');

function handleUpdate() {
const suffix = this.dataset.sizing || '';
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
}

inputs.forEach(input => input.addEventListener('change', handleUpdate));
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
</script>

</body>
Expand Down
52 changes: 50 additions & 2 deletions 04 - Array Cardio Day 1/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,80 @@
'Berne, Eric', 'Berra, Yogi', 'Berry, Wendell', 'Bevan, Aneurin', 'Ben-Gurion, David', 'Bevel, Ken', 'Biden, Joseph', 'Bennington, Chester', 'Bierce, Ambrose',
'Billings, Josh', 'Birrell, Augustine', 'Blair, Tony', 'Beecher, Henry', 'Biondo, Frank'
];

// Array.prototype.filter()
// 1. Filter the list of inventors for those who were born in the 1500's
const fifteen = inventors.filter(inventor => (inventor.year >= 1500 && inventor.year < 1600))

console.table(fifteen);

// Array.prototype.map()
// 2. Give us an array of the inventors first and last names
const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`);
console.log(fullNames);

// Array.prototype.sort()
// 3. Sort the inventors by birthdate, oldest to youngest
// const ordered = inventors.sort(function(a, b) {
// if(a.year > b.year) {
// return 1;
// } else {
// return -1;
// }
// });

const ordered = inventors.sort((a, b) => a.year > b.year ? 1 : -1); // Array.prototype.reduce()

console.table(ordered);

// Array.prototype.reduce()
// 4. How many years did all the inventors live all together?
const totalYears = inventors.reduce((total, inventor) => {
return total + (inventor.passed - inventor.year);
}, 0);

console.log(totalYears);

// 5. Sort the inventors by years lived
const oldest = inventors.sort(function(a, b) {
const lastGuy = a.passed - a.year;
const nextGuy = b.passed - b.year;
return lastGuy > nextGuy ? -1 : 1;
});
console.table(oldest)

// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris

const category = document.querySelector('.mw-category');
const links = Array.from(document.querySelectorAll('a'));
const de = links
.map(link => link.textContent)
.filter(streetName => streetName.includes('de'));


// 7. sort Exercise
// Sort the people alphabetically by last name
const alpha = people.sort(function(lastOne, nextOne) {
const [aLast, aFirst] = lastOne.split(', ');
const [bLast, bFirst] = nextOne.split(', ');
return aLast > bLast ? 1 : -1;
});
console.log(alpha);

// 8. Reduce Exercise
// Sum up the instances of each of these
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];

const transportation = data.reduce(function(obj, item) {
if(!obj[item]) {
obj[item] = 0;
}
obj[item]++;
return obj;
}, {});

console.log(transportation);

</script>
</body>
</html>
29 changes: 29 additions & 0 deletions 05 - Flex Panel Gallery/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
.panels {
min-height: 100vh;
overflow: hidden;
display: flex;
}

.panel {
Expand All @@ -44,6 +45,11 @@
font-size: 20px;
background-size: cover;
background-position: center;
flex: 1;
justify-content: center;
align-items: center;
display: flex;
flex-direction: column;
}

.panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
Expand All @@ -57,8 +63,17 @@
margin: 0;
width: 100%;
transition: transform 0.5s;
flex: 1 0 auto;
display: flex;
justify-content: center;
align-items: center;
}

.panel > *:first-child { transform: translateY(-100%); }
.panel.open-active > *:first-child { transform: translateY(0); }
.panel > *:last-child { transform: translateY(100%); }
.panel.open-active > *:last-child { transform: translateY(0); }

.panel p {
text-transform: uppercase;
font-family: 'Amatic SC', cursive;
Expand All @@ -71,6 +86,7 @@
}

.panel.open {
flex: 5;
font-size: 40px;
}

Expand Down Expand Up @@ -106,7 +122,20 @@
</div>

<script>
const panels = document.querySelectorAll('.panel');

function toggleOpen() {
this.classList.toggle('open');
}

function toggleActive(e) {
if (e.propertyName.includes('flex')) {
this.classList.toggle('open-active');
}
}

panels.forEach(panel => panel.addEventListener('click', toggleOpen));
panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));
</script>


Expand Down
41 changes: 41 additions & 0 deletions 06 - Type Ahead/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,47 @@
<script>
const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json';

const cities = [];

fetch(endpoint)
.then(blob => blob.json())
.then(data => cities.push(...data));

function findMatches(wordToMatch, cities) {
return cities.filter(place => {
const regex = new RegExp(wordToMatch, 'gi');
return place.city.match(regex) || place.state.match(regex)
});
}

function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

function displayMatches() {
const matchArray = findMatches(this.value, cities);
const html = matchArray.map(place => {
const regex = new RegExp(this.value, 'gi');
const cityName = place.city.replace(regex, `<span class="h1">${this.
value}</span>`);
const stateName = place.state.replace(regex, `<span class="h1">${this.
value}</span>`);
return `
<li>
<span class="name">${place.city}, ${place.state}</span>
<span class="population">${numberWithCommas(place.population)}</span>
</li>
`;
}).join('');
suggestions.innerHTML = html;
}

const searchInput = document.querySelector('.search');
const suggestions = document.querySelector('.suggestions');

searchInput.addEventListener('change', displayMatches);
searchInput.addEventListener('keyup', displayMatches);

</script>
</body>
</html>
26 changes: 25 additions & 1 deletion 07 - Array Cardio Day 2/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,40 @@

// Some and Every Checks
// Array.prototype.some() // is at least one person 19 or older?

const isAdult = people.some(person => ((new Date()).
getFullYear()) - person.year >= 19);

console.log({isAdult});

// Array.prototype.every() // is everyone 19 or older?

// Array.prototype.find()
const allAdults = people.every(person => ((new Date()).
getFullYear()) - person.year >= 19);

console.log({allAdults});

// Array.prototype.find()
// Find is like filter, but instead returns just the one you are looking for
// find the comment with the ID of 823423

const comment = comments.find(comment => comment.id === 823423);

console.log(comment);

// Array.prototype.findIndex()
// Find the comment with this ID
// delete the comment with the ID of 823423

const index = comments.findIndex(comment => comment.id === 823423);

console.log(index);

const newComments = [
...comments.slice(0, index),
...comments.slice(index + 1)
];

</script>
</body>
</html>
51 changes: 51 additions & 0 deletions 08 - Fun with HTML5 Canvas/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,57 @@
<body>
<canvas id="draw" width="800" height="800"></canvas>
<script>
const canvas = document.querySelector('#draw');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
ctx.strokeStyle = '#BADASS';
ctx.lineJoin = 'round';
ctx.lineCap = 'round';
ctx.lineWidth = 100;
ctx.globalCompositeOperation = 'multiply';

let isDrawing = false;
let lastX = 0;
let lastY = 0;
let hue = 0;
let direction = true;

function draw(e) {
if (!isDrawing) return; // stop the fun from running when they are not moused down
console.log(e);
ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`;
ctx.beginPath();
// start from
ctx.moveTo(lastX, lastY);
// got to
ctx.lineTo(e.offsetX, e.offsetY);
ctx.stroke();
[lastX, lastY] = [e.offsetX, e.offsetY];

hue++;
if(hue >= 360) {
hue = 0;
}
if(ctx.lineWidth >= 100 || ctx.lineWidth <= 1) {
direction = !direction;
}
if(direction) {
ctx.lineWidth++;
} else {
ctx.lineWidth--;
}

}

canvas.addEventListener('mousedown', (e) => {
isDrawing = true;
[lastX, lastY] = [e.offsetX, e.offsetY];
});

canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseup', () => isDrawing = false);
canvas.addEventListener('mouseout', () => isDrawing = false);
</script>

<style>
Expand Down
Loading