Grow your CSS skills. Land your dream job.

Cross fade images on hash change?

  • # May 8, 2011 at 7:16 pm

    Using the hash change tutorial on this site, I was wondering if there was a way to cross fade images on hash changes, each page has a featured image and I am wondering if on hash change you can fade in the new image over the top of the existing image so you get the cross fade effect instead of fading to white and then fading in the image.

    Here is the JS I am using so far:

    $(function() {

    // Load pages on nav click
    var newHash = "",
    $mainContent = $("#main"),
    $featuredContent = $("#featured-wrap"),
    $el;

    $("#sidebar li").delegate("a", "click", function()
    {
    window.location.hash = $(this).attr("href");
    return false;
    });

    $(window).bind('hashchange', function()
    {
    newHash = window.location.hash.substring(1);

    if(newHash)
    $mainContent.find("#guts, #featured").fadeOut(200, function()
    {
    $mainContent.hide().load(newHash + " #guts", function()
    {
    $mainContent.fadeIn(200);
    });

    $featuredContent.hide().load(newHash + " #featured", function()
    {
    $featuredContent.fadeIn(200);
    });

    $("#sidebar li a").removeClass("active");
    $("#sidebar li a[href='"+newHash+"']").addClass("active");
    });

    });

    $(window).trigger('hashchange');

    });

    And here is a typical page’s HTML

            < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">















    Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus






Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".