javascript - JQuery mobile - Use transitions without using changePage -
i using jqm 1.4 , backbone together.
in beginning of project, using config file disable jqm router , use backbone 1 instead, called jqm "changepage" method programmatically on hash change.
but i've got problems making work want, while need changepage css3 transition.
the best option have find way use jquery mobile transitions (slide, pop, fade...) without using changepage. if use transitions on divs, perfect.
any clue on how ? know there fine libraries effeckt.css think jqm more mobile-cross-browser compatible (correct me if wrong).
animation classes in jquery mobile can found here. use them, need add animation class name e.g. fade
plus animation class, either in
or out
.
moreover, make sure remove classes after animation
ends listening animationend
event.
$("element") .addclass("in pop") .one('webkitanimationend mozanimationend msanimationend oanimationend animationend', function () { $(this) .removeclass("in pop"); /* remove animation classes */ });
update 1
check browser's animation/transition support, below should return true
.
$.support.cssanimations $.support.csstransitions $.support.csstransform3d
for example
if (!$.support.cssanimations) { /* don't animate */ }
update 2
the default fallback transition browsers don't support transform3d fade
. below code updated reflect checking whether current browser supports transform3d.
details
let's want animate below divs dynamically in
or out
.
<!-- buttons demo --> <a href="#" class="ui-btn ui-btn-inline" data-custom="in">animate-in</a> <a href="#" class="ui-btn ui-btn-inline" data-custom="out">animate-out</a> <!-- divs --> <div class="animatediv" data-transition="pop"></div> <div class="animatediv" data-transition="flip"></div>
add data-transition
attribute div
should be equal animation class. also, add data-custom
or custom data
attribute define in direction divs animated, whether in
or out
.
then control them js.
$(document).on("pagecreate", function (e, ui) { /* check support */ var support = $.support.csstransform3d && $.support.csstransitions && $.support.cssanimations ? true : false; $(".ui-btn").on("click", function () { var direction = $(this).data("custom"); /* in or out */ $(".animatediv").each(function () { var animation = support ? $(this).data("transition") + " " + direction : "fade " + direction; /* set "fade" if support false */ $(this).addclass(animation); }); }); $(document).on("webkitanimationend mozanimationend msanimationend oanimationend animationend", ".out, .in", function (e) { var outorin = $(this).hasclass("in") ? "in" : "out", animated = support ? $(this).data("transition") : "fade"; $(this).removeclass(animated); }); });
Comments
Post a Comment