-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate materialize css and remove babel (#6)
* remove step 1 * modify deps * add animations * fix: image not in manifest * 1.0.0-alpha.10
- Loading branch information
Showing
31 changed files
with
743 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/node_modules | ||
/src | ||
/.babelrc | ||
/.gitignore | ||
/webpack.config.js | ||
/yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,41 @@ | ||
|
||
/** | ||
* get scroll top | ||
* @returns {number} | ||
*/ | ||
const getScrollTop = () => { | ||
return document.documentElement.scrollTop || document.body.scrollTop; | ||
export const timings = { | ||
'ease-in-out': (x) => { | ||
return (x * x) / (2 * x * x - 2 * x + 1); | ||
}, | ||
'linear': (x) => x | ||
} | ||
|
||
/** | ||
* set scroll top | ||
* @param {number} top | ||
*/ | ||
export const setScrollTop = (top) => { | ||
document.body.scrollTop = top; // For Safari | ||
document.documentElement.scrollTop = top; // For Chrome, Firefox, IE and Opera | ||
} | ||
|
||
/** | ||
* Scroll to the specific position | ||
* @param {number} pos position | ||
* @param {number} time million second | ||
*/ | ||
export const scrollTo = (pos, time = 500, onend) => { | ||
const timefn = x => x*x / (x*x + (1-x)*(1-x)); | ||
const last = Date.now(); | ||
const lastpos = getScrollTop(); | ||
const fn = (now) => { | ||
now = Date.now() - last; | ||
if (now < time) { | ||
const nowpos = (pos - lastpos) * timefn(now / time) + lastpos; | ||
setScrollTop(nowpos); | ||
requestAnimationFrame(fn); | ||
} else { | ||
setScrollTop(pos); | ||
onend && onend(); | ||
export const walk = (step, duration = 200, timing = timings['ease-in-out']) => { | ||
return new Promise((resolve) => { | ||
const start = Date.now(); | ||
const fn = () => { | ||
const now = Date.now(); | ||
if (now - start >= duration) { | ||
step(1); | ||
resolve(); | ||
} else { | ||
step(timing((now - start) / duration)); | ||
requestAnimationFrame(fn); | ||
} | ||
} | ||
} | ||
requestAnimationFrame(fn); | ||
} | ||
|
||
/** | ||
* fly to element | ||
* @param {string} el selector | ||
*/ | ||
export const flyToElement = (el) => { | ||
// fake invoke | ||
if (!el) return; | ||
|
||
console.log('Scrolling to ' + el); | ||
|
||
const elem = document.querySelector(el); | ||
if (!elem) { | ||
console.warn('Cannot find element: ' + el); | ||
return; | ||
} | ||
const target = getScrollTop() + elem.getBoundingClientRect().top; | ||
elem.classList.remove('xepub-highlight'); | ||
|
||
scrollTo(target - 100, 500, () => { | ||
elem.classList.add('xepub-highlight'); | ||
|
||
requestAnimationFrame(fn); | ||
}); | ||
} | ||
|
||
/** | ||
* fly to an element or top without animations | ||
* @param {string} el selector | ||
*/ | ||
export const flyToElementImmediately = (el) => { | ||
|
||
if (!el) { | ||
setScrollTop(0); | ||
return; | ||
} | ||
|
||
const elem = document.querySelector(el); | ||
if (!elem) { | ||
setScrollTop(0); | ||
return; | ||
export const animate = async (target, dest, duration = 200, timing = timings['ease-in-out']) => { | ||
const from = { }; | ||
for (const key in dest) { | ||
if (typeof dest[key] === 'number') { | ||
from[key] = parseFloat(target.style[key]); | ||
} | ||
} | ||
const target = getScrollTop() + elem.getBoundingClientRect().top; | ||
|
||
setScrollTop(target - 100); | ||
await walk((x) => { | ||
for (const key in from) { | ||
const now = (dest[key] - from[key]) * x + from[key]; | ||
target.style[key] = now + 'px'; | ||
} | ||
}, duration, timing); | ||
} | ||
|
Oops, something went wrong.