Home › Forums › JavaScript › Cross fade images on hash change?
- This topic is empty.
-
AuthorPosts
-
May 8, 2011 at 7:16 pm #32645mikes02Participant
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
Untitled Document
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
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.