Last active
May 7, 2017 10:52
-
-
Save AntonLitvin/2eba8daa9266ad95f6b629cfec8d55cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
$('.hover').bind('touchstart touchend', function(e) { | |
e.preventDefault(); | |
$(this).toggleClass('hover-effect'); | |
}); | |
}); | |
In english: | |
when you start or end a touch, turn the class hover-effect on or off. | |
Then, in your HTML, add a class hover to anything you want this to work with. In your CSS, replace any instance of: | |
element:hover { | |
rule:properties; | |
} | |
with | |
element:hover, element.hover-effect { | |
rule:properties; | |
} | |
And just for added usefulness, add this to your CSS as well: | |
.hover { | |
-webkit-user-select: none; | |
-webkit-touch-callout: none; | |
} | |
To stop the browser asking you to copy/save/select the image or whatever. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment