mirror of
https://gitea.invidious.io/iv-org/videojs-vtt-thumbnails.git
synced 2024-08-15 00:43:16 +00:00
Fix position calcualtion
This commit is contained in:
parent
8e88f57e1c
commit
3d6c6709e2
3 changed files with 9279 additions and 5 deletions
9264
package-lock.json
generated
Normal file
9264
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "videojs-vtt-thumbnails",
|
"name": "videojs-vtt-thumbnails",
|
||||||
"version": "0.0.8",
|
"version": "0.0.9",
|
||||||
"description": "Display thumnails on progress bar hover, driven by external VTT files.",
|
"description": "Display thumnails on progress bar hover, driven by external VTT files.",
|
||||||
"main": "dist/videojs-vtt-thumbnails.cjs.js",
|
"main": "dist/videojs-vtt-thumbnails.cjs.js",
|
||||||
"module": "dist/videojs-vtt-thumbnails.es.js",
|
"module": "dist/videojs-vtt-thumbnails.es.js",
|
||||||
|
|
|
@ -68,6 +68,7 @@ class vttThumbnailsPlugin {
|
||||||
constructor (player, options) {
|
constructor (player, options) {
|
||||||
this.player = player
|
this.player = player
|
||||||
this.options = options
|
this.options = options
|
||||||
|
this.listenForDurationChange();
|
||||||
this.initializeThumbnails();
|
this.initializeThumbnails();
|
||||||
this.registeredEvents = {};
|
this.registeredEvents = {};
|
||||||
return this;
|
return this;
|
||||||
|
@ -97,6 +98,12 @@ class vttThumbnailsPlugin {
|
||||||
delete this.lastStyle;
|
delete this.lastStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listenForDurationChange() {
|
||||||
|
this.player.on('durationchange', () => {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap the plugin.
|
* Bootstrap the plugin.
|
||||||
*/
|
*/
|
||||||
|
@ -183,7 +190,7 @@ class vttThumbnailsPlugin {
|
||||||
|
|
||||||
onBarMousemove (event) {
|
onBarMousemove (event) {
|
||||||
this.updateThumbnailStyle(
|
this.updateThumbnailStyle(
|
||||||
event.clientX - this.progressBar.offsetLeft,
|
event.clientX - (this.progressBar.offsetLeft + this.player.el().offsetLeft),
|
||||||
this.progressBar.offsetWidth
|
this.progressBar.offsetWidth
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -209,10 +216,13 @@ class vttThumbnailsPlugin {
|
||||||
const duration = this.player.duration()
|
const duration = this.player.duration()
|
||||||
const time = ((1 - ((width - x) / width))) * duration
|
const time = ((1 - ((width - x) / width))) * duration
|
||||||
const currentStyle = this.getStyleForTime(time)
|
const currentStyle = this.getStyleForTime(time)
|
||||||
|
|
||||||
if (!currentStyle) {
|
if (!currentStyle) {
|
||||||
return this.hideThumbnailHolder()
|
return this.hideThumbnailHolder()
|
||||||
}
|
}
|
||||||
|
|
||||||
const xPos = ((1 - ((width - x) / width))) * width
|
const xPos = ((1 - ((width - x) / width))) * width
|
||||||
|
|
||||||
this.thumbnailHolder.style.transform = 'translateX(' + xPos + 'px)'
|
this.thumbnailHolder.style.transform = 'translateX(' + xPos + 'px)'
|
||||||
this.thumbnailHolder.style.marginLeft = '-' + (parseInt(currentStyle.width) / 2) + 'px'
|
this.thumbnailHolder.style.marginLeft = '-' + (parseInt(currentStyle.width) / 2) + 'px'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue