2010-07-21 76 views
3

我使用jQTouch(及其内置动画)开发iPhone版的网站。所以,我有一个静态菜单:如何捕捉jQTouch动画完成?

<ul class="rounded"> 
    <li class="arrow"><a href="#item1" class="fade">Item 1</a></li> 
    <li class="arrow"><a href="#item2" class="fade">Item 2</a></li> 
    <li class="arrow"><a href="#item3" class="fade">Item 3</a></li> 
    <li class="arrow"><a href="#item4" class="fade">Item 4</a></li> 
</ul> 

这是包含在一些div的。我的问题是隐藏与hash链接相同的项目divid,它属于location.hash,并且与用户在此页面上时相同。

因此,链接上的click事件(将用户移动到另一个带动画的div)并不合适,因为location.hash仅在动画完成时才会更改。

这就是问题:如何捕捉jQTouch动画完成来解决问题?也许我可以用jQuery自己做,但是怎么做?

谢谢。

编辑: 我找到了解决方案。所以,我在这里发布。

$('body > div').bind('pageAnimationEnd', function(){ 

    //wait a bit for the end of the animation 
    //and hash change 
    setTimeout(function(){ 

     //current div id 
     divId = '#' + $('.current .toolbar + .section').parent().attr('id'); 

     //test whether there's a link to the same page 
     link = $(divId + ' .rounded li').find('a[href='+divId+']'); 

     if ( divId == location.hash  
      && link.length > 0) 
     { 
      $('a[href='+divId+']').parent().fadeOut(0); 
     } 
     else 
     { 
      $('a[href='+divId+']').parent().fadeIn(0); 
     } 
     }, 100);    
    }); 
+0

哈哈!这就是所谓的'只是谷歌它!'...人们,粘贴到谷歌'jqtouch事件',第一个链接将传递给谷歌存储库的关于jQTouch回调事件,http://code.google。 COM/p/jqtouch /维基/ CallbackEvents。 – franzose 2010-07-21 06:03:02

回答

0

这是否适用于Safari和Chrome? 对我来说,它只适用于Firefox。

+0

我很久没有做过什么。据我所知,它只适用于Webkit。因为jQTouch专为Apple的移动开发而设计。我们当时停止了移动开发的探索,现在我正在等待jQuery Mobile。这是真正的跨平台的东西,因为他们承诺。 – franzose 2010-11-02 03:21:32