Add a Twitter for iPhone Style Swipe Menu to jQuery Mobile

Filed under: jQuery Mobile

comments (13) Views: 84,253

This article is over a year old and has not been updated. Your results may vary.

In my recent blog post on adding iPhone style swipe to delete button in jQuery Mobile I promised that I'd give you a part two, adding an entire "swipe menu". Well, here it is. Here's a screenshot of what we'll be building. Note that we're using plain text buttons instead of icons, but you can modify this to your heart's content. We're using this same setup in several areas of the Goba.mobi mobile website. If you'd like to see this code in action, check out the demo

Here's the listview code. Again, it's just plain HTML. To spice things up a little I added a second row of text. Can you handle the excitement?

The basic JavaScript code is the same, with a few minor exceptions. I won't cover the same pieces again, just focusing on the new ones.

I found that somehow jQuery Mobile was assigning the swiperight event twice, so I'm explicitly removing the swiperight event before binding it again. In this case, we're inserting the buttons into the menu node, then inserting the menu node into the list element. To add a little extra flair I'm animating the menu in from the left (following the slide of the finger). Finally I wanted a way to close the menu so that I could get to the element beneath it. I assign an event to the body of the page so that I can "click away" from the menu and have it close.

Lastly the CSS for the menu, and a generic button definition to give it the size and position I wanted.

And that's it. Take a look at the finished product on your smart phone to see it in action. I hope you've enjoyed this tutorial and can put the contents to good use on your jQuery Mobile powered website.

Amazon logo

If this article was interesting, or helpful, or even wrong, please consider leaving a comment, or buying something from my wishlist. It's appreciated!

Related Posts


comments powered by Disqus
coach outlet online jordan 13 grey toe beats by dre cyber monday michael kors black friday beats by dre cyber monday jordan 6 black infrared north face cyber monday michael kors cyber monday north face black friday coach outlet black infrared 23 13s north face cyber monday jordan 6 black infrared north face black friday coach cyber monday jordan 11 legend blue north face cyber monday black infrared 6s lebron 12 north face black friday jordan 11 legend blue louis vuitton outlet jordan 13 grey toe grey toe 13s beats by dre black friday coach black friday jordan 13 grey toe coach cyber monday uggs black friday jordan 13 black infrared 23 uggs cyber monday barons 13s uggs black friday beats by dre cyber monday black infrared 6s jordan 13 bred jordan 13 black infrared 23 north face black friday black infrared 6s jordan 11 legend blue michael kors black friday jordan 13 grey toe coach black friday michael kors black friday michael kors cyber monday beats by dre cyber Monday north face cyber monday coach black friday michael kors cyber monday beats by dre cyber Monday north face black friday beats by dre black friday lululemon black friday uggs black friday jordan 13 bred coach cyber monday beats by dre black friday uggs black friday coach black friday black infrared 6s