init
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
return function (config, element) {
|
||||
var video = element.querySelector('video');
|
||||
|
||||
if (!video) {
|
||||
return;
|
||||
}
|
||||
|
||||
function playVideo() {
|
||||
try {
|
||||
video.currentTime = 0;
|
||||
} catch (error) {}
|
||||
|
||||
element.classList.add('is-playing');
|
||||
video.play().catch(function () {});
|
||||
}
|
||||
|
||||
function stopVideo() {
|
||||
video.pause();
|
||||
element.classList.remove('is-playing');
|
||||
}
|
||||
|
||||
element.addEventListener('mouseenter', playVideo);
|
||||
element.addEventListener('mouseleave', stopVideo);
|
||||
|
||||
element.addEventListener('click', function (event) {
|
||||
if (event.target.closest('a')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (video.paused) {
|
||||
playVideo();
|
||||
} else {
|
||||
stopVideo();
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user