简体   繁体   English

jQuery:切换下拉菜单的可能性

[英]jQuery: Toggle Dropdown Menu Possibility

I have the following HTML below but what I was wanting to know is it possible to use the jQuery .toggle function to enable the main <li> heading Trails to be a link and then when you put the mouse over the main link Trails the other pages will show and you can click on the respective page. 我在下面有以下HTML,但是我想知道的是,可以使用jQuery .toggle函数来使主<li>标题Trails成为链接,然后将鼠标放在主链接上Trails其他将显示页面,您可以单击相应页面。

HTML: - This HTML formatting is given by PYROCMS and I have no control over it HTML: - 这种HTML格式是由PYROCMS提供的,我对此无能为力

<li class="current">
        <a href="">Trials</a>
        <ul>
            <li class="first">
                <a href="">Link One</a>
            </li>
            <li>
                <a href="">Link Two</a>
            </li>
            <li>
                <a href="">Link Three</a>
            </li>
            <li class="last">
                <a href="">Link Four</a>
            </li>
        </ul>
    </li>

jQuery: - Could a variation of the below be used for the above issue? jQuery: - 可以将以下版本用于上述问题吗?

$('select[name="domainTransfer"]').change(function() {

    $('#domainToBeTransfered,#domainToBeTransfered0').toggle($(this).val() === "yes");

    });

Baz1nga: Baz1nga:

I have looked at your jsfiddle and noticed you have placed a display:none; 我查看了您的jsfiddle,发现您放置了display:none; on the sub <ul> I have placed that into my css the line is #wrapper #contentarea #blue_box .centerblue_txt ul li ul{ but it does not seem to interact with the jQuery. 在子<ul>我已经在CSS中输入了#wrapper #contentarea #blue_box .centerblue_txt ul li ul{但它似乎与jQuery没有交互。

jQuery(document).ready(function () {
    $(".current a").mouseenter(function(){
       $(this).siblings("ul").show();
    }).mouseout(function(){
       $(this).siblings("ul").hide();
    });​
});​
$(".current a").mouseenter(function(){
   $(this).siblings("ul").show();
}).mouseleave(function(){
   $(this).siblings("ul").hide();
});

Is this what you want? 这是你想要的吗?

Demo: http://jsfiddle.net/rY8zm/ 演示: http//jsfiddle.net/rY8zm/

Baz1nga's solution isn't working for me in Opera. Baz1nga的解决方案不适用于Opera。 The list dies when the cursor transits from the heading to the list - hence the list can be viewed but its links can never be clicked. 当光标从标题过渡到列表时,该列表消失,因此可以查看该列表,但永远不能单击其链接。

You need to take special measures to see the cursor through the transition from element to element. 您需要采取特殊措施,才能看到从一个元素到另一个元素的过渡中的光标。 This achieved with a timeout to delay very lightly the hiding of the list; 通过超时可以非常轻松地延迟列表的隐藏。 and the canceling of the timeout each time the cursor passes over any element that should keep the list alive. 并在每次光标经过应该使列表保持活动状态的任何元素时取消超时。

The code is moderately complex and looks like this: 代码相当复杂,看起来像这样:

function hideList($list) {
    clearTimeout($list.data('dropdown').tim);
    return setTimeout(function() {
        $list.stop(true).slideUp('slow');
    }, 125);
}

$("li.current").on('mouseover', "a.heading", function() {
    var $list = $(this).siblings("ul").slideDown('slow');
    clearTimeout($list.data('dropdown').tim);
}).on('mouseout', function() {
    var $list = $(this).children("ul");
    $list.data('dropdown').tim = hideList($list);
}).children("ul").on('mouseover', function() {
    clearTimeout($(this).data('dropdown').tim);
}).on('mouseout', function() {
    var $list = $(this);
    $list.data('dropdown').tim = hideList($list);
}).data('dropdown', {
    tim: null
}).hide();

See fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM