いつも大変お世話になっております。
下記コードでドロップダウンメニューを動作させておりますが
ios(iphone,ipadなど)だけaタグが機能せずクリックしてもリンクしません。
どうかお助け下さいませ。
html
<nav class="g-navi-2" id="main-menu"> <ul class="clearfix"> <li class="lvl1"><a href="#">サンプルタイトル</a> <div class="lvl2" style="width: 215px;"> <div class="lvl2-inner"> <div class="col_1_small"> <nav> <ul> <li><a href="sample.html" >サンプル</a></li> <li><a href="sample.html" >サンプル</a></li> <li><a href="sample.html" >サンプル</a></li> <li><a href="sample.html" >サンプル</a></li> </ul> </nav> </div> </div> </div> </li> <li class="lvl1"><a href="#">サンプルタイトル</a> <div class="lvl2" style="width: 215px; left: 22rem; border-right:1px solid #fff;"> <div class="lvl2-inner"> <div class="col_1_small"> <nav> <ul> <li><a href="sample.html" >サンプル</a></li> <li><a href="sample.html" >サンプル</a></li> </ul> </nav> </div> </div> </div> </li> </ul> </nav>
js(ソースコードに直書き)
<script type="text/javascript"> $(document).ready(function () { $('#main-menu').trevoMegaMenu({ type: 'hover' }); }); </script>
js
(function ($) { $.fn.trevoMegaMenu = function (options) { var defaults = { type: "hover", fadeIn: 200, fadeOut: 200 }; var options = $.extend(defaults, options); return this.each(function () { $(this).find("li.lvl1 a").each(function () { if ((options.type == "click") || ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)))) { $(this).click(function () { subMenu = $(this).parent().find(".lvl2"); if (subMenu.is(":visible")) { $(this).parent().find(".lvl2").fadeOut(options.fadeOut); } else { $(this).parent().find(".lvl2").fadeIn(options.fadeIn); if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) { $(this).parent().find(".lvl2").bind('touchstart click', function () { $(this).fadeOut(options.fadeOut) }) } } }); } else { $(this).hover(function () { var lvl2Element = $(this).parent().find(".lvl2"); if (lvl2Element[0]) { $(this).click(function () { return false }) }; lvl2Element.fadeIn(options.fadeIn); $(this).parent().find(".lvl2").hover(function () { clearTimeout(trvTimer); }, function () { var e = $(this); setTimeout(function () { if (!e.parent().children("a").ismouseover()) { e.fadeOut(options.fadeOut); } }, 100); }) }, function () { $(this).parent().children(".lvl2").each(function () { var e = $(this); trvTimer = setTimeout(function () { e.fadeOut(options.fadeOut); }, 100); }) }); } }) }); }; })(jQuery); (function ($) { $.mlp = { x: 0, y: 0 }; function documentHandler() { var $current = this === document ? $(this) : $(this).contents(); $current.mousemove(function (e) { jQuery.mlp = { x: e.pageX, y: e.pageY } }); $current.find("iframe").load(documentHandler); } $(documentHandler); $.fn.ismouseover = function (overThis) { var result = false; this.eq(0).each(function () { var $current = $(this).is("iframe") ? $(this).contents().find("body") : $(this); var offset = $current.offset(); result = offset.left <= $.mlp.x && offset.left + $current.outerWidth() > $.mlp.x && offset.top <= $.mlp.y && offset.top + $current.outerHeight() > $.mlp.y; }); return result; }; })(jQuery);
あなたの回答
tips
プレビュー