Last active
December 20, 2017 15:08
-
-
Save ingozoell/7dc7f37d6eb00e3a162420ea6df4c21f to your computer and use it in GitHub Desktop.
Drop-Down Navigation: Responsive and Touch-Friendly (moseover, hover)
https://osvaldas.info/drop-down-navigation-responsive-and-touch-friendly
This file contains 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
/* | |
By Osvaldas Valutis, www.osvaldas.info | |
Available for use under the MIT License | |
*/ | |
;(function( $, window, document, undefined ) { | |
$.fn.doubleTapToGo = function( params ) { | |
if( !( 'ontouchstart' in window ) && | |
!navigator.msMaxTouchPoints && | |
!navigator.userAgent.toLowerCase().match( /windows phone os 7/i ) ) return false; | |
this.each( function() { | |
var curItem = false; | |
$( this ).on( 'click', function( e ) | |
{ | |
var item = $( this ); | |
if( item[ 0 ] != curItem[ 0 ] ) | |
{ | |
e.preventDefault(); | |
curItem = item; | |
} | |
}); | |
$( document ).on( 'click touchstart MSPointerDown', function( e ) { | |
var resetItem = true, | |
parents = $( e.target ).parents(); | |
for( var i = 0; i < parents.length; i++ ) | |
if( parents[ i ] == curItem[ 0 ] ) | |
resetItem = false; | |
if( resetItem ) | |
curItem = false; | |
}); | |
}); | |
return this; | |
}; | |
})( jQuery, window, document ); |
This file contains 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
/* WP */ | |
$(function () { | |
$('.touch #navi .menu-item-has-children > a').not('.sub-menu a').doubleTapToGo(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment