I am using Jimdo and have a given div (containing 3 sub-divs, I think this is my general problem, but I am not sure) I found with the browser:
<div class="jtpl-background-area jqbga-container jqbga-web--image" background-area="" style="background-image: url('https://image.jimcdn.com/app/cms/image/transf/dimension=767x/path/s4354a59fbfee63e4/backgroundarea/ibb91266a7f033fa3/version/1529172695/image.jpg');background-position: 54.0833% 41.0025%;"></div>
How do I get a function triggered after the background-image of this is loaded?
I've already spent hours into this, tried tons of ways I found here or tools like waitforimages - still without success. What is going on with Jimdo / this div? How do I get something triggered after the background-image is loaded?
var src = $('.jtpl-background-area').css('background-image');
var url = src.match(/\((.*?)\)/)[1].replace(/('|")/g,'');
var img = new Image();
img.onload = function() {
$('.jtpl-background-area').css('-webkit-animation', 'fadein 4s');
}
img.src = url;
if (img.complete) img.onload();
does not work.
$('.jtpl-background-area').waitForImages(true).done(function() {
$('.jtpl-background-area').css('-webkit-animation', 'fadein 4s');
});
does not work (waitforimages-script is included correct and opacity of .jtpl-background-area is set to 0 in css).
Any ideas?
$(window).on('load', function() {
$(".jtpl-background-area").css('-webkit-animation', 'fadein 4s');
});
causes backgrounds often popping up too late. Page is displayed while pictures are still not ready/fully loaded.
-
Edit:
Regarding Scott Marcus and the answer here by 'adeneo' (Wait for background images in CSS to be fully loaded):
$(window).on('load', function() {
$(".jtpl-background-area jqbga-container jqbga-web-
image").ready(function() {
$(".jtpl-background-area").velocity({ opacity: 1 },{ duration: 3000});
})
});
This here "works" - but my bg-images popping up too late. But why does nothing happen if I exchange this with
var src = $(".jtpl-background-area jqbga-container jqbga-web-image");
var url = src.match(/\((.*?)\)/)[1].replace(/('|")/g,'');
var img = new Image();
img.onload = function() {
$('.jtpl-background-area').velocity({ opacity: 1 },{ duration: 3000});
}
img.src = url;
if (img.complete) img.onload();
? Where is my mistake? Why doesnt this work and make my page stuck? It stays white and fails to load at all with this code.
Or in other words - how do I get
var src = $('#test').css('background-image');
var url = src.match(/\((.*?)\)/)[1].replace(/('|")/g,'');
var img = new Image();
img.onload = function() {
alert('image loaded');
}
img.src = url;
if (img.complete) img.onload();
to work with my (given and unchangeable)
<div class="jtpl-background-area jqbga-container jqbga-web--image" background-area="" style="background-image: url('https://image.jimcdn.com/app/cms/image/transf/dimension=767x/path/s4354a59fbfee63e4/backgroundarea/ibb91266a7f033fa3/version/1529172695/image.jpg');background-position: 54.0833% 41.0025%;"></div>
exactly?