Home › Forums › CSS › Preloading background images that are in an inline style › Re: Preloading background images that are in an inline style
January 10, 2013 at 7:45 am
#120508
Participant
Maybe you need to set a fake attribute to store the background like this:
<div class="preload" id="main"<?php if ( $thumbnail_id = get_post_thumbnail_id() ) {
if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'normal-bg' ) )
printf( ' data-background="background-image: url(%s);"', $image_src[0] );}?>>
Then, with JQuery you set a new `style` attribute with the value taken from `data-background` attribute value:
$('.preload').each(function() {
$(this).attr('style', $(this).data('background'));
});