Skip to content

Instantly share code, notes, and snippets.

@jeangontijo
Last active June 14, 2018 14:40
Show Gist options
  • Save jeangontijo/78e45998eada64afc0b6554d9d7a1a6f to your computer and use it in GitHub Desktop.
Save jeangontijo/78e45998eada64afc0b6554d9d7a1a6f to your computer and use it in GitHub Desktop.
Hover on Touch
// Replace :hover for .hover
var card = document.querySelectorAll('.card');
Array.prototype.slice.call(card).forEach(function(item) {
item.addEventListener('touchstart', function(e) {
this.classList.toggle("hover");
}, false);
item.addEventListener('mouseenter', function(e) {
this.classList.add("hover");
}, false);
item.addEventListener('mouseleave', function(e) {
this.classList.remove("hover");
}, false);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment