-2

On my webshop www.spidercatcher.dk I want the background vid only to show on PC, and then have a still photo on phones and tablets, it kinda works when I set a poster tag, but I cannot scale the poster tag properly, so the image is too large on phones, plus the margin is weird.

Can anyone help? The website is set up in Wordpress, Woocommerce, with Flatshop theme.

Here is the HTML and CSS code:

video# bgvid {
    position: static;
    margin - top: -15 % ;
    min - width: 100 % ;
    min - height: 100 % ;
    width: auto;
    height: auto;
    z - index: -100;
    background: transparent url(/wp-content/uploads / 2016 / 04 / Spidercatcher_vid_frame.jpg) no - repeat 0 0; - webkit - background - size: cover; - moz - background - size: cover; - o - background - size: cover;
    background - size: cover;
}
<video autoplay loop poster="/wp-content/uploads/2016/04/Spidercatcher_vid_frame.png" id="bgvid">
  <source src="/wp-content/uploads/2016/04/Spidercatcher_vid.mp4" type="video/mp4">
</video>
Milap
  • 6,096
  • 8
  • 21
  • 44
FlendtDK
  • 1
  • 1

5 Answers5

0

Don't do this with CSS, The image/video will still download (Higher load time). Use PHP for this problem.

0

its easy you need to use media query CSS . for mobile and table devices

@media only screen and (max-width: 600px) {

video#bgvid {
display:none;
}

}

Same you can set it as per your screen size

@media only screen and (max-width: 320px) {


}

http://www.w3schools.com/css/css_rwd_mediaqueries.asp

http://cssmediaqueries.com/

Jitendra Popat
  • 2,086
  • 1
  • 12
  • 13
0

as @juul van bracht added, it's not good idea to play with css for hiding it on mobile.

best and most efficient way is to go with php/wordpress functions:

<?php
if (!wp_is_mobile()) {?>
    <video autoplay loop poster="/wp-content/uploads/2016/04/Spidercatcher_vid_frame.png" id="bgvid">
    <source src="/wp-content/uploads/2016/04/Spidercatcher_vid.mp4" type="video/mp4">
    </video>
<?php } else { ?>
    <img src="whatever.jpeg"/>
<?php }  ?>
Nirpendra Patel
  • 669
  • 7
  • 20
  • If I past this into the hook content, nothing actually changes, it still looks like this on phone: [link](http://i.imgur.com/oL9gQyz.jpg) – FlendtDK May 04 '16 at 11:15
0

This can be achieved using media queries, or through using a framework such as Modernizr.

It may be easier to think about your question as "how do I add a video background to devices that will display it properly." By removing the video from the basic website and adding it in later using either a media query, or modernizr. you can also remove the Video from other browsers that may also have difficulty in displaying a video. For instance screen readers for blind people.

Basic actions for all approaches

Firstly rewrite your page for what you want the most basic browser to see. Think about the worst phone based browser from 10-15 years ago, working over a dialup connection, or alternatively what you want people to see when they print your page onto paper.

CSS media Query Approach

Set the visibility of the video block to hidden. Then add in the video effects for browsers over a certain screen size (say 700px)

@media only screen and (min-width: 700px) {
video#bgvid {
visibility: visible 
}

This will still mean that all browsers download the video, and slow down the page.

jQuery approach

You can do the same using jQuery and Javascript

if(window.screen.width >700){
$("#bgvid").html("<video>...</video>")

Other

There are other approaches you can take here to achieve this, look at frameworks like Modernizr. but essentially if you go the other way around - ie build the site for a mobile device, then add what a device can take, you may be better off. I would generally suggest that jQuery tends to be more pleasing than CSS media queries. In my experience, you tend to experience fewer problems with incompatible browsers.

Grimley
  • 97
  • 10
  • I have not yet tried this solution, but I actually totally forgot about media queries, however I have a Samsung Galaxy S7, with a resolution of 1440x2560px, so by blocking it below 700px, won't change it on my phone? Link to how it looks on phone: http://i.imgur.com/oL9gQyz.jpg – FlendtDK May 04 '16 at 11:18
  • Absolutely correct - Detecting a mobile device is a moving target (see http://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery – Grimley May 04 '16 at 14:36
  • Just as an aside - I Use my browser on a portrait oriented screen - the video from your site looks similar on my desktop screen. This may be because you have set the min-height to 100% after you have set the min-width to 100%. CSS in some browsers does not change the aspect ratio of the video. It may be better to decide whether it's more important to get the video width in the frame, or the height. – Grimley May 04 '16 at 14:52
0

If your video is inside a div and you are trying:

 var video = document.getElementById('video_id');
 video.src = "" 

That won't work. You have to do something like this:

document.querySelectorAll('#video')[0].src = "';