Can't Fade Background Image in jQuery? Try This
While attempting to fade a background image using jQuery, several approaches have proved unsuccessful, including:
var x = 0; while (true) { /* change background-image of #slide using some variation of animate or fadeIn/fadeOut with or without setTimeout */ x++; }
Solution:
The key to this issue lies in the fact that jQuery cannot directly fade background images. To work around this, use tags to represent your images and initially hide them using display: none;. Set their position to absolute and z-index to -1 to mimic background behavior, forcing them to appear behind all other elements.
Here's an example of how to achieve this effect:
HTML:
<img src="/static/imghwm/default1.png" data-src=".." class="lazy" alt="Can\'t Fade Background Image in jQuery? Unlock the Solution" > <img src="/static/imghwm/default1.png" data-src=".." class="lazy" alt="Can\'t Fade Background Image in jQuery? Unlock the Solution" >
CSS:
img{ position:absolute; z-index:-1; display:none; }
jQuery:
function test() { $("img").each(function(index) { $(this).hide(); $(this).delay(3000 * index).fadeIn(3000).fadeOut(); }); } test();
A live demonstration is available at http://jsfiddle.net/RyGKV/.
The above is the detailed content of Can\'t Fade Background Image in jQuery? Unlock the Solution. For more information, please follow other related articles on the PHP Chinese website!

Having a "parent selector" in CSS is mentioned regularly as something CSS could really use. I feel like I've had that thought plenty of times myself, but then

In this week's news: Firefox gets strict, Opera goes to the dark side, and Chrome plans to let web apps run in the background.

We just ran a fancy article series here on CSS-Tricks with a bunch of different articles all answering the same question. By fancy, I mean two things:

One of the many (many) useful things that Jetpack does is give you extra-fancy custom blocks in the WordPress block (AKA Gutenberg) editor: a slideshow,

Seemingly out of the blue, the Gulp processing I had set up for this site started to have a race condition. I'd run my watch command, change some CSS, and the

For those who may not come from a design background, selecting a color palette is often based on personal preferences. Choosing colors might be done with an

These are tongue-in-cheek, but there is a point to be made here. It's one challenge to understand a technology, and another challenge to understand how

As is the rule in WebGL, anything that seems like it should be simple is actually quite complicated. Drawing lines, debugging shaders, text rendering… they


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)