Jump to content

Stop Mobile Fallback Image From Showing on Desktop

Recommended Posts

Posted

Site URL: https://menuez.com/

I have a cover page with an auto-play video background for desktop that is replaced with a fallback image on mobile. The mobile fallback image flashes on screen before the video starts playing on desktop. Is there any way to disable the fallback image from showing on desktop or replace it with a background color while retaining image on mobile?

Posted (edited)

This jQuery code will change the image to blank.gif for 4 seconds and then change it back to your image.  You can adjust the time if needed, but it seem like the video loads in that amount of time.

If you don't want to upload a blank image, it looks like this is free to use. https://en.wikipedia.org/wiki/File:Clear.gif but confirm for yourself on the usage stuff.

var imgSRC = $('.custom-fallback-image').attr('src');
$('.custom-fallback-image').attr('src', 'blank.gif');

$(document).ready(function () {
  setTimeout(function () {
      $('.custom-fallback-image').attr('src', imgSRC);
  }, 4000);
});

 

Edited by rwp
Posted

So I can't seem to get it to work. I have the latest jQuery Core in the site-wide code injection footer & your code injected between <script></script> tags on the page itself but I'm still seeing the mobile fallback flash before the video starts. Am I doing something wrong? Thank You!

On 6/24/2020 at 5:46 PM, rwp said:

var imgSRC = $('.custom-fallback-image').attr('src'); $('.custom-fallback-image').attr('src', 'blank.gif'); $(document).ready(function () { setTimeout(function () { $('.custom-fallback-image').attr('src', imgSRC); }, 4000); });

Posted

Hm... Can't get it to work... tried injecting jQuery in site-wide header & footer, as well as page header both with it's own <script> tags & without as in attached screenshot.

Screenshot (369).png

Posted (edited)

Ya, I noticed after I posted; had it right the first time! Pointing to a wikimedia commons blank .jpg now but still nothing... 

 

Screenshot (399).png

Edited by DevonLois
Posted

Indeed; looks like that 's' was missing; rest of the code is the same for Core 3.5.1. I'm using minified version; tried uncompressed & slim as well - still nothing!

Posted (edited)

So my thoughts are that the code is running before the fallback image is actually generated, so lets try this.....

We can also get rid of the blank image, I should have thought of that earlier.

Replace the old code that I gave you with this, keep the script tags, keep the jquery script, just replace whats in yellow.......

$(document).ready(function () {
  $('.custom-fallback-image').attr('style', 'display: none');
  setTimeout(function () {
      $('.custom-fallback-image').attr('style', 'display: block');
  }, 4000);
});

 

image.png

Edited by rwp
Posted

Amazing! Thank you thank you thank you for helping with this odd issue - now we see a bit of grey before the video instead of the mobile fallback flashing for half a second. Awesome.

 

Quote

$(document).ready(function () {
  $('.custom-fallback-image').attr('style', 'display: none');
  setTimeout(function () {
      $('.custom-fallback-image').attr('style', 'display: block');
  }, 4000);
});

 

  • 2 months later...
Posted

Can you guys copy and past the whole code need to make this work.

I take it this goes in the 'Page > Settings > Advanced' as opposed to 'Design > Custom CSS' right?

Using the latest Squrespace templates 7.1?

Posted
On 10/8/2020 at 8:04 PM, joelygoe said:

Can you guys copy and past the whole code need to make this work.

I take it this goes in the 'Page > Settings > Advanced' as opposed to 'Design > Custom CSS' right?

Using the latest Squrespace templates 7.1?

Have you solved this yet?

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted

I have tried pasting the below code into the "Page Settings > Advanced > Code" but it doesn't work.  Just leaves code in the header visible on the page.

 

https://www.nintaidojo.co.uk/history

 

$(document).ready(function () {
  $('.custom-fallback-image').attr('style', 'display: none');
  setTimeout(function () {
      $('.custom-fallback-image').attr('style', 'display: block');
  }, 4000);
});
Posted
23 hours ago, joelygoe said:

I have tried pasting the below code into the "Page Settings > Advanced > Code" but it doesn't work.  Just leaves code in the header visible on the page.

 

https://www.nintaidojo.co.uk/history

 


$(document).ready(function () {
  $('.custom-fallback-image').attr('style', 'display: none');
  setTimeout(function () {
      $('.custom-fallback-image').attr('style', 'display: block');
  }, 4000);
});

wrap code in script tag

<script>

your code

</script>

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted (edited)

Okay - I have (hand typed) all this code into it.  Still doesn't work!

<script> 
 src="https://code.jquery.com/jquery-3.5.1.min.js" 
 integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"> 

</script> 

<script> 
var imgSRC = $('.cussom-fallback-image').attr('src'); 
$('.custcm-fallback-image') .attr('src',
'https://commons.wikimedia.org/wiki/Category:Solid_white_images#/media/File:Broad_blank_space.jpg'); 

$(document).ready(function () {
  $('.custom-fallback-image').attr('style', 'display: none');
  setTimeout(function () {
      $('.custom-fallback-image').attr('style', 'display: block');
  }, 4000);
});
</script>

Edited by joelygoe
Posted
<script> 
 src="https://code.jquery.com/jquery-3.5.1.min.js" 
 integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"> 

</script> 

<script> 
var imgSRC = $('.cussom-fallback-image').attr('src'); 
$('.custcm-fallback-image') .attr('src',
'https://commons.wikimedia.org/wiki/Category:Solid_white_images#/media/File:Broad_blank_space.jpg'); 

$(document).ready(function () {
  $('.custom-fallback-image').attr('style', 'display: none');
  setTimeout(function () {
      $('.custom-fallback-image').attr('style', 'display: block');
  }, 4000);
});
</script>

 

  • 2 months later...
Posted
On 10/15/2020 at 3:53 AM, joelygoe said:

<script> 
 src="https://code.jquery.com/jquery-3.5.1.min.js" 
 integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"> 

</script> 

<script> 
var imgSRC = $('.cussom-fallback-image').attr('src'); 
$('.custcm-fallback-image') .attr('src',
'https://commons.wikimedia.org/wiki/Category:Solid_white_images#/media/File:Broad_blank_space.jpg'); 

$(document).ready(function () {
  $('.custom-fallback-image').attr('style', 'display: none');
  setTimeout(function () {
      $('.custom-fallback-image').attr('style', 'display: block');
  }, 4000);
});
</script>

Were you able to solve this? I am trying to solve the same thing as you above and none of the code works for me.

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.