I emphasize once again: the task is not to display a random image. The set of images and their addresses on the server are strictly specified.
Task: update the pictures on the site, because The contents of the image files may change. Physically, the image file remains at the same address, but since the contents of the file may change, you must force the browser to update the displayed image forcibly. For this timer add parameter to the image address
setInterval(function(){ var arr = $(".image-responsive"); for (var i = 0; i < arr.length; i++ ){ arr[i].style.backgroundImage = 'url(' + arr[i].style.backgroundImage.slice(4, -1).replace(/"/g, "").split("?")[0] + "?" + Math.random() + ')'; } }, 1000); Images are updated, but there is a delay before each update and the background remains empty for some time. Also the background appears abruptly. How to fix it to remove jerking and pause?
Update 2: I tried to use a preloader, an invisible container into which images are loaded, before setting them as background images for the necessary blocks on the page. With one picture to remove jerking turned out http://jsfiddle.net/rGkww/36/ However, scrolling twitches. With several http://jsfiddle.net/rGkww/41/, only one picture changes, the picture jerks as before, and the scrolling twitches
Update 3: It seems to have removed the jerking, an example of a code with a lot of images http://jsfiddle.net/rGkww/57/ It remains to jerk the scroll, well, not quite sure about the correctness of the solution itself. The page should be designed for long-term work.
Update 4: Removed scrolling jerking http://jsfiddle.net/rGkww/61/
Update 5:
I modified the code a bit so that in the event of a disconnection from the server there was no memory overflow, and after the restoration the update was resumed. http://jsfiddle.net/rGkww/64/ Update occurs without problems. However, Iceweasel/Firefox drops in a couple of hours. Because long work is necessary, it is critical. It is unclear whether the problem is in the code or in the browser. Chrome/Chromium quietly works for several days.
arr[i].style.backgroundImage = arr[i].style.backgroundImage;and then immediatelyarr[i].style.backgroundImage = 'url(' + arr[i].style.backgroundImage.slice(4, -1).replace(/"/g, "").split("?")[0] + "?" + Math.random() + ')';Anyway, the background image is twitching - EmmImage()constructor. use it, do not create any elements, on theonloadalready insert a picture into the background. Your question has already been answered, but for some reason you do not want to admit it, insisting that YOUR implementation be changed, although the xaja implementation works - ThisMan