Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 812219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:10:09+00:00 2026-05-15T01:10:09+00:00

I’m currently using this code: var gallery = $(‘ul#gallery’).children(); $(gallery).filter(‘:even’).not(‘:last’).hover(function () {$(this).toggleClass(‘next’)}); I’m trying

  • 0

I’m currently using this code:

var gallery = $('ul#gallery').children();

$(gallery).filter(':even').not(':last').hover(function () {$(this).toggleClass('next')});

I’m trying to make it fade this new class in. Currently, there’s an <li> with an image in it, no background. When the ‘next’ class is added, it gives it a background image when hovered over. Is there a way to just fade in the new class without making the image blink/fade at all?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:10:10+00:00Added an answer on May 15, 2026 at 1:10 am

    If you have jQueryUI installed, you can fade animate a class by adding a duration.

    $(this).toggleClass('next', 500);
    

    http://jqueryui.com/demos/toggleClass/

    But as far as I know, there is no separate opacity setting that affects only the background image. So if you want to fade that in, you would need to fade the entire element, which, as you stated, is not what you want.

    If you really want the effect, an alternative may be to prepend a separate element to the one you were giving the class, and fade in that element (with its background image).

    The element would need to have absolute positioning so that it doesn’t affect the rest of the content.

    You would end up with something like:

    CSS:

    li {
        position: relative;
    }
    
    .background {
        width: 100%;
        height: 100%;
        background:orange;  // This would be your background image instead
        position: absolute;
        top: 0;
        left: 0;
    }
    
    .content {
        position: relative;
    }
    

    HTML:

    <ul id='gallery'>
            <li>
                <div class='background'></div>  // Prepend and fade in
                <div class='content'>hi there</div>
            </li>
    </ul>
    

    jQuery:

    hover() takes two functions. One when you mouseenter, the other when you mouseleave.

    // Set opacity to 0 for all .background elements
    $(‘.background’).css({opacity: 0});

    var gallery = $('ul#gallery').children();
    
    gallery.filter(':even').not(':last').hover(
      function () {
           $(this).find('.background').animate({'opacity': 1}, 500);
      },
      function () {
           $(this).find('.background').animate({'opacity': 0}, 500);
    });
    

    EDIT:

    FYI, you can change your selector to get what you want right away without having to call .filter(), and so on.

    var gallery = $('ul#gallery li:even:not(:last)');
    
    gallery.hover(...
    

    EDIT:

    Changed wording in first sentence and added link to docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.