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

  • SEARCH
  • Home
  • 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 8810829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:12:49+00:00 2026-06-14T03:12:49+00:00

Right now, I’m using switchClass to change the body backgound. The change is instant

  • 0

Right now, I’m using switchClass to change the body backgound. The change is instant and not easy on the eyes.

$('.Click').click(function () {
    var thisClass = $(this).attr('class');
    var st = thisClass.split(' ');
    var firstClass = st[0];

    if (firstClass == "item1") {
        $('.mask').animate({
            marginLeft: "-100%"
        }, 600, function () {
            $("body").switchClass($("body").attr("className"), "bg1");
        });
    } else if (firstClass == "item2") {
        $('.jobsMask').animate({
            marginLeft: "-200%"
        }, 600, function () {
            $("body").switchClass($("body").attr("className"), "bg2");
        });
    }
});

How do I animate this / make this less abrupt?

  • 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-06-14T03:12:50+00:00Added an answer on June 14, 2026 at 3:12 am

    For background-color fading:

    You can use a transition on the body element to animate changes to the background property like this:

    body { 
      -ms-transition: background 0.8s ease 0s;
      -moz-transition: background 0.8s ease 0s;
      -o-transition: background 0.8s ease 0s;
      -webkit-transition: background 0.8s ease 0s;
      transition: background 0.8s ease 0s;  
    }
    

    test it: http://jsbin.com/odabit/2/edit


    For fading background images:

    Transitions don’t seem to work on background-image (EDIT: they work in Chrome, but not in Fx16, Opera12.1, or IE9), so my workaround is to put your bg images on separate divs, and then fade those in and out, like this: http://jsbin.com/odabit/7/edit

    The switching code looks like this:

    var cls1 = 'bg1', cls2 = 'bg2',
      body = $('body'),
      bg1 = body.hasClass(cls1) ||  !!body.children('.'+cls1)[0],
      bg = bg1 ? body.children('.'+cls1) : body.children('.'+cls2),
      newBg;
    
    if (!bg[0]) {
    bg = $('<div>', {'class': (bg1 ? cls1 : cls2)}).prependTo(body);
    }
    
    newBg =  $('<div>', {'class': (bg1 ? cls2 : cls1)}).insertAfter(bg).hide();
    
    body.removeClass(cls1 +' ' +cls2);
    
    bg.fadeOut('slow', function() { bg.remove(); });
    newBg.fadeIn('slow');
    

    And the CSS to support it:

    body > div[class^="bg"] {
      position: fixed;
      top: 0; right: 0; bottom: 0; left: 0;
      z-index: -1;
    }
    
    .bg1 {
      background: url(/* image 1 */);
    }
    
    .bg2 {
     background: url(/* image 2 */); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

right now i have this <script type='text/javascript'> $(#beau).click(function(){ $(#beau).animate({margin-Top: 738px}, fast); }); </script> and
Right now im using css to create an onclick image change. The problem is
Right now I have a function, in a class that is used to listen
Right now I am using sqlite within a ios application, and I want to
Right now I'm using the jQuery selector $('foo+bar') . Since I already have $('foo')
Right now I am only trying to get my getline() function to work. I
Right now I am using learning to program for the iphone and I am
Right now I am not specifying it and the system is defaulting to text/html
Right now I'm using the following command to compile a coffeescript file each time
Right now I'm using OleDbDataAdapter objDataReader = new OleDbDataAdapter(); objDataReader.SelectCommand = myCommand; objDataReader.Fill(myDataTable); But

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.