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

Added background transition effect #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 19 additions & 1 deletion monocle/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ window.onload = () => {
const originalListItems = originalList.innerHTML;
originalList.parentNode.removeChild( originalList );

// Body
const body = document.querySelector('body');

// Top list
const listA = document.createElement( 'div' );
listA.className = 'list-wrapper list-a';
Expand Down Expand Up @@ -42,6 +45,7 @@ window.onload = () => {

window.addEventListener( 'resize', layout );
window.addEventListener( 'scroll', syncScrollPosition );
window.addEventListener('scroll', changeBackground);

wrapper.style.visibility = '';

Expand Down Expand Up @@ -83,11 +87,25 @@ window.onload = () => {

scrollPosition = window.scrollY / scrollRange;
scrollPosition = Math.max( 0, Math.min( 1, scrollPosition ) );

sync();

}

function getColor() {
let color = "#" + Math.random().toString(16).slice(2, 8);
if(color.toLowerCase() === "#ffffff") {
getColor();
}
return color;
}

function changeBackground() {
let color = scrollPosition == 0 ? '#000000' : getColor();
body.style.background = color;
}

//console.log(body);

init();

};
4 changes: 3 additions & 1 deletion monocle/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ html {
overflow: auto; }

body {
height: 500%; }
height: 500%;
transition: background-color 1s ease;
}

.page-wrapper {
position: fixed;
Expand Down