現在、私は.wrapper1
要素で私のネストされたリストを表示するには、私のCSSで:hover
を使用しています。ホバー上ではなくクリックで開くようにしたい。ここで表示要素:ホバー
は、私がこれまで試したものです:
$(function() {
// whenever we hover over a menu item that has a submenu
$('li.parent').on('click', function() {
var $menuItem = $(this),
$submenuWrapper = $('> .wrapper', $menuItem);
// grab the menu item's position relative to its positioned parent
var menuItemPos = $menuItem.position();
// place the submenu in the correct position relevant to the menu item
$submenuWrapper.css({
top: menuItemPos.top,
left: menuItemPos.left + Math.round($menuItem.outerWidth() * 0.75)
});
});
});
デモ:以下https://jsfiddle.net/72tnxh45/2/
は、すべてのサブリンクを表示するように影響を与えることができるCSSです。
.wrapper1 li:hover > .wrapper1 {
display: block;
}
、あなたはjQueryのをインポートする必要があります。ここでは[更新されたフィドル](https://jsfiddle.net/72tnxh45/2/) – 4castle
私のコードでは、jqueryが含まれています。 –