Skip to content

Instantly share code, notes, and snippets.

@serialpark
Forked from c-kick/hnl.taphover.js
Last active April 1, 2016 09:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save serialpark/ef5172de76bdd52414b4 to your computer and use it in GitHub Desktop.
Save serialpark/ef5172de76bdd52414b4 to your computer and use it in GitHub Desktop.
//taphover - a solution to the lack of hover on touch devices.
//more info: http://www.hnldesign.nl/work/code/mouseover-hover-on-touch-devices-using-jquery/
$('a.taphover').on('touchstart', function (e) {
'use strict'; //satisfy the code inspectors
var link = $(this); //preselect the link
if (link.hasClass('hover')) {
//preventDefault and return false will cause any other touches on the element(s) to fail.
//to avoid this behavior data() will store the "href". so "href" can be restored.
link.attr("href", link.data("href"));
} else {
link.addClass('hover');
$('a.taphover').not(this).removeClass('hover');
link.data("href", link.attr("href")).removeAttr("href").css("cursor","pointer");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment