Data-transition effects does not work with tab navigation jquery mobile

断了今生、忘了曾经 提交于 2019-12-22 10:23:38

问题


I try to bring some effects to my tabs navigation on my jquery-mobile page but it looks like that the data-transitions argument does not work combined with a tabs navigation.

My code looks like this:

<div data-role="header" data-theme="a" id="header">
<h1>Mainpage</h1>
</div>

<div data-role="main" class="ui-content">
<div data-role="tabs" id="tabs" >
  <div data-role="navbar" data-iconpos="left">
    <ul>
        <li><a id="lblTab1" href="#location" data-ajax="false" class="ui-btn-active" data-icon="search" data-transition="pop">search</a></li>
        <li><a id="lblTab2" href="#product" data-ajax="false" data-icon="location" data-transition="pop">product</a></li>
    </ul>
  </div>
  <div id="location" class="ui-body-d ui-content" > content </div>
  <div id="product" class="ui-body-d ui-content" > content2  </div>
</div>
</div>
</div>

so how is it possible to bring some effects to the navigation bar?

I use jquery-mobile 1.4.0


回答1:


Page transitions don't work on tabs as transition classes are activated when hiding/showing pages. You can create your own transitions, use third party CSS transitions or use jQM default ones.

First, you need to listen to tabbeforeactivate event. This event omits a ui object containing data of previous (ui.oldPanel) and next panel (ui.newPanel). All you need is to add animation classes to ui-newPanel and remove them once animation ends by binding Animation End one time only using .one().

$("#tabs").on("tabbeforeactivate", function (e, ui) {
  $(ui.newPanel)
      .addClass("animation")
      .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
    $(this).removeClass("animation");
  });
});

Demo - Custom animation by Daneden

Demo - jQM default transitions



来源:https://stackoverflow.com/questions/21975173/data-transition-effects-does-not-work-with-tab-navigation-jquery-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!