Skip to content

Commit

Permalink
Merge pull request #222 from marp-team/restart-animation-when-switchi…
Browse files Browse the repository at this point in the history
…ng-page

Restart CSS animations when switching page in bespoke template
  • Loading branch information
yhatt authored Jun 8, 2020
2 parents efc0a81 + 0049923 commit 0737e35
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- Add a trailing slash to the directory links on server index page to avoid broken path resolution ([#221](https://github.com/marp-team/marp-cli/pull/221) by [@n-ari](https://github.com/n-ari))
- Restart CSS animations when switching page in bespoke template ([#222](https://github.com/marp-team/marp-cli/pull/222))

### Changed

Expand Down
7 changes: 7 additions & 0 deletions src/templates/bespoke/bespoke.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ $progressHeight: 5px;
opacity: 1;
pointer-events: auto;
z-index: 0;

&.bespoke-marp-active-ready {
* {
/* Reset animation: "none" keyword does not reset animation in Firefox */
animation-name: __bespoke_marp__ !important;
}
}
}

&[data-bespoke-marp-load='hideable'] {
Expand Down
14 changes: 12 additions & 2 deletions src/templates/bespoke/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ export default function bespokeClasses(deck) {
deck.slides.map((element) => element.classList.add('bespoke-marp-slide'))

deck.on('activate', (e) => {
deck.slides.map((element) =>
element.classList.remove('bespoke-marp-active')
const shouldResetAnimation = !e.slide.classList.contains(
'bespoke-marp-active'
)

deck.slides.map((element) => {
element.classList.remove('bespoke-marp-active')
})
e.slide.classList.add('bespoke-marp-active')

if (shouldResetAnimation) {
e.slide.classList.add('bespoke-marp-active-ready')
void document.body.clientHeight
e.slide.classList.remove('bespoke-marp-active-ready')
}
})
}
14 changes: 9 additions & 5 deletions src/templates/bespoke/presenter/next-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ export default function nextView(deck) {
const [dir, args] = e.data.split(':')

if (dir === 'navigate') {
const [idx, fragIdx] = args.split(',')
const [sIdx, sFragIdx] = args.split(',')
let idx = Number.parseInt(sIdx, 10)
let fragment = Number.parseInt(sFragIdx, 10) + 1

deck.slide(Number.parseInt(idx, 10), {
fragment: Number.parseInt(fragIdx, 10),
})
deck.next()
if (fragment >= deck.fragments[idx].length) {
idx += 1
fragment = 0
}

deck.slide(idx, { fragment })
}
}

Expand Down

0 comments on commit 0737e35

Please sign in to comment.