如何从这个.hover函数.click函数

How to make from this .hover function a .click function

本文关键字:函数 hover click      更新时间:2023-09-26

我如何从这个。hover函数。click函数?

if ($(window).width() > 992) {
    $('.navbar-main-slide .navbar-nav > .dropdown').hover(function () {
        "use strict";
        $(this).addClass('open').find('.dropdown-menu').first().stop(true, true).delay(500).slideDown();
    }, function () {
        "use strict";
        var na = $(this);
        na.find('.dropdown-menu').first().stop(true, true).delay(100).slideUp('fast', function () {
            na.removeClass('open');
        });
    });
}

我不太明白你的问题,你是否尝试过将hover更改为click功能?

if ($(window).width() > 992) {
    $('.navbar-main-slide .navbar-nav > .dropdown').click(function () {
        "use strict";
        $(this).addClass('open').find('.dropdown-menu').first().stop(true, true).delay(500).slideDown();
    }, function () {
        "use strict";
        var na = $(this);
        na.find('.dropdown-menu').first().stop(true, true).delay(100).slideUp('fast', function () {
            na.removeClass('open');
        });
    });
}

或者你可以试试这个

if ($(window).width() > 992) {
        $('.navbar-main-slide .navbar-nav > .dropdown').click(function () {
            $(this).toggleClass('open').find('.dropdown-menu').first().stop(true, true).delay(500).slideToggle();
        }
    }