mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-03 14:52:38 +00:00
Add brew bounce animation
This commit is contained in:
@@ -43,7 +43,8 @@ const Editor = createClass({
|
|||||||
},
|
},
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
view : 'text' //'text', 'style', 'meta'
|
view : 'text', //'text', 'style', 'meta'
|
||||||
|
isBrewScrolling : false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -189,7 +190,28 @@ const Editor = createClass({
|
|||||||
brewJump : function(targetPage=this.getCurrentPage()){
|
brewJump : function(targetPage=this.getCurrentPage()){
|
||||||
if(!window || this.isMeta()) return;
|
if(!window || this.isMeta()) return;
|
||||||
// console.log(`Scroll to: p${targetPage}`);
|
// console.log(`Scroll to: p${targetPage}`);
|
||||||
window.frames['BrewRenderer'].contentDocument.getElementById(`p${targetPage}`).scrollIntoView({ behavior: 'smooth', block: 'start' });
|
const currentPos = window.frames['BrewRenderer'].contentDocument.getElementsByClassName('brewRenderer')[0].scrollTop;
|
||||||
|
const targetPos = window.frames['BrewRenderer'].contentDocument.getElementById(`p${targetPage}`).getBoundingClientRect().top;
|
||||||
|
const interimPos = targetPos >= 0 ? -30 : 30;
|
||||||
|
|
||||||
|
const bounceDelay = 100;
|
||||||
|
const scrollDelay = 500;
|
||||||
|
|
||||||
|
if(!this.state.isBrewScrolling) {
|
||||||
|
this.setState({
|
||||||
|
isBrewScrolling : true
|
||||||
|
});
|
||||||
|
window.frames['BrewRenderer'].contentDocument.getElementsByClassName('brewRenderer')[0].scrollTo({ top: currentPos + interimPos, behavior: 'smooth' });
|
||||||
|
setTimeout(()=>{
|
||||||
|
window.frames['BrewRenderer'].contentDocument.getElementsByClassName('brewRenderer')[0].scrollTo({ top: currentPos + targetPos, behavior: 'smooth', block: 'start' });
|
||||||
|
}, bounceDelay);
|
||||||
|
setTimeout(()=>{
|
||||||
|
this.setState({
|
||||||
|
isBrewScrolling : false
|
||||||
|
});
|
||||||
|
}, scrollDelay);
|
||||||
|
}
|
||||||
|
|
||||||
// const hashPage = (page != 1) ? `p${page}` : '';
|
// const hashPage = (page != 1) ? `p${page}` : '';
|
||||||
// window.location.hash = hashPage;
|
// window.location.hash = hashPage;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user