Fixing the Hover event on the iPad/iPhone/iPod

Note: This information may now be out of date. It was published in 2010!

In truth it’s not a fix as the iPad doesn’t have the ability to hover.

Apple has developed extra events to replace hover on it’s mobile touch devices. I’ve recently been working a lot on the iPad and came across the problem of hovered navigation not showing up. It’s a css :hover event that fires through a CSS selector on an <a> element with no href attribute.

To emulate the hover we simply add an event listener to the element we want to have a hover event. In jQuery we do this (make sure you insert it into document.ready):

//ipad and iphone fix
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    $(".menu li a").click(function(){
        //we just need to attach a click event listener to provoke iPhone/iPod/iPad's hover event
        //strange
    });
}

That should enable the element to be touched, and stimulate and iPad hover event.

If you’re having problems getting hovered elements to fire you could also try using touchstart or touchend which is probably a better method depending on what you’re trying to accomplish:


if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
    $(".menu li a").bind('touchstart', function(){
        console.log("touch started");
    });

    $(".menu li a").bind('touchend', function(){
        console.log("touch ended");
    });

}

The things that annoy me about iPhone 3.0

Don’t get me wrong, the new updates for the iPhone are a much needed modification for the device. Cut/Copy & Paste, Tethering and MMS are all things which should (in my opinion) have been on the phone from the very first incarnation. These things were standard on even the most basic of modern phones.

Apple have played it clever. They brought out an amazing phone and missed out a lot of the basics. The annoying thing though is the fact that Apple is shouting about simple things such as “Read and write texts, emails and picture messaging holding your iPhone sideways.“. Wow! “Cut Copy Paste, Move text, numbers, email addresses between apps“. Honest to god these are not major selling points for the new iPhone software so why flaunt them? To say these are only 2 of the most flaunted updates how good can the other 98 be? Thank god Apple have updated the website today to show the other top features such as the search function, stereo bluetooth and the new language support.

Overall I’m happy with the new update and look forward to installing it next Wednesday (June 17th) but I can’t help but feel Apple have been deliberately holding this off for 2 years just to drum up a bit of cash/publicity. Classic Apple/Jobs, and to be honest, it’s worked on me, as ashamed as I am to say it, I’ll probably be on the phone to o2 next week about upgrading to the 3G S (which is a crap name by the way). :-D