javascript - fadeIn and fadeOut effect between pages -
i'm trying make transition effects page.
the goal fade in page when first enter, , when click link, page fadeout , fadein destination page. won't destination url when click link, url changes www.example.com/#undefined
any suggestions?
jquery.holdready(true); jquery("body").css("opacity", 0); jquery.holdready(false); jquery(function ($) { $("body").fadeto(1500, 1); $(document).on("click", "a", function (event) { event.preventdefault(); $("body").fadeto(1500, 0, function () { // href attribute var newurl = $(this).attr("href"); // veryfy if new url exists or hash if (!newurl || newurl[0] === "#") { // set hash location.hash = newurl; return; } // now, fadeout html (whole page) $("body").fadeto(1500, 1, function () { // when animation complete, set new location location = newurl; }); // prevent default browser behavior. return false; }); }); });
within inner function, this doesn't point @ <a> element clicked. move resolution of newurl outside of function:
jquery.holdready(true); jquery("body").css("opacity", 0); jquery.holdready(false); jquery(function ($) { $("body").fadeto(1500, 1); $(document).on("click", "a", function (event) { // href attribute // "this" still <a> element here var newurl = $(this).attr("href"); event.preventdefault(); $("body").fadeto(1500, 0, function () { //here, trying url, "this" //points animated element, ie body // veryfy if new url exists or hash if (!newurl || newurl[0] === "#") { // set hash location.hash = newurl; return; } //just update location without fading in @ point location = newurl; // prevent default browser behavior. return false; }); }); });
Comments
Post a Comment