NOTE: I am not talking CSS media queries which can show or hide the video - that will still load it on a mobile device.
So in essence i am looking for "media queries in JavaScript" so that i can completely destroy the object and recreate it as needed.
What i found was this:
Vide for showing the video (i know i could do it by hand, but this jquery library does have one or two advantages in my case): GitHub - https://github.com/VodkaBears/Vide#readme
Then i discovered the creator of Vide had the same problem, as stated here:
Code: Select all
Hey @b3nhartl3y. I'm having to do this myself, and I've found an option if you don't mind using another plugin (it is lightweight). Harvey.js is basically media queries in javascript: http://harvesthq.github.io/harvey/
So in the JS, you'll want something like:
Harvey.attach('screen and (min-width: 600px)', {
on: function() {
$('.home-hero').vide({
// your stuff here
});
},
off: function() {
var instance = $('.home-hero').data('vide');
instance.destroy();
}
});
I've used 600px as an example minimum width. If the device is larger than that, it will follow 'on' and activate/load the Video. If it is smaller, you can grab your video instance and destroy it. That should mean that the video isn't loaded on mobile. Worked when I tested it on mobile.
But for the life of me i cannot get it to work. If someone knows of a better way to do this or perhaps can help me get this going, it would be much appreciated. Next step is moving over to the commercial help section if it turns out that it is harder than expected.
I have this in HTML:
Code: Select all
<div id="videoBackground" style="width: 100%; height: 400px;"
data-vide-bg="{root_url}/uploads/drive" data-vide-options="loop: false, muted: true, position: 0% -60%, resizing: true">
</div>
Code: Select all
$(function(){
Harvey.attach('screen and (min-width: 600px)', {
on: function() {
$('#videoBackground').vide("{root_url}/uploads/drive"), {
muted: true,
loop: false,
autoplay: true,
position: '0% -60%',
resizing: true,
};
},
off: function() {
var instance = $('#videoBackground').data('vide');
instance.destroy();
}
});
});