pinafore/src/routes/_components/AutoplayVideo.html
Nolan Lawson 4bd181d3cc
fix: update Sapper to latest (#775)
* fix: update to latest sapper

fixes #416

* fix error and debug pages

* requestIdleCallback makes column switching feel way nicer than double rAF

* add export feature

* add better csp info

* workaround for sapper sub-page issue

* clarify in readme about exporting

* fix now config

* switch from rIC to triple raf

* style-loader is no longer used

* update theming guide
2018-12-11 07:31:48 -08:00

61 lines
1.4 KiB
HTML

<div class="autoplay-wrapper {$largeInlineMedia ? '' : 'autoplay-video-fixed-size'}"
style="width: {width}px; height: {height}px;"
>
<video
class="autoplay-video {$largeInlineMedia ? '' : 'autoplay-video-fixed-size'}"
aria-label={ariaLabel || ''}
style="{focusStyle} background-image: url({poster}); "
{poster}
{width}
{height}
{src}
autoplay
muted
loop
webkit-playsinline
playsinline
/>
</div>
<style>
.autoplay-wrapper {
position: relative;
margin: 0;
padding: 0;
}
.autoplay-video {
background-repeat: no-repeat;
background-position: center;
background-size: cover;
display: flex;
}
.autoplay-video-fixed-size {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
<script>
import { store } from '../_store/store'
import { coordsToPercent } from '../_utils/coordsToPercent'
export default {
data: () => ({
focus: void 0
}),
store: () => store,
computed: {
focusStyle: ({ focus }) => {
// Here we do a pure css version instead of using
// https://github.com/jonom/jquery-focuspoint#1-calculate-your-images-focus-point
if (!focus) return 'background-position: center;'
return `object-position: ${coordsToPercent(focus.x)}% ${100 - coordsToPercent(focus.y)}%;`
}
}
}
</script>