JS Hide drop-down menu once the mouse moves away

  • Last update:  2020-12-18
  • I. Overview

    1.1 Problem

    When clicking on the drop-down widget, a menu will appear. But if we want to collapse the menu, we must select an item or click elsewhere first. How can the menu be collapsed once the mouse moves away?

    js-6.gif


    1.2 Solution

    We can add the JS initialization event to the widget.

    Note: This does not support mobile devices.

    II. Example

    Design the report: add the drop-down box widget, and set the data dictionary of the options.

    image.png

    Add an after initialization event to the widget:

    image (1).png

    var self = this;
    window.tryCollapse = function() {
        if (window.needCollapse) {
            if (self.isExpanded()) {
                self.collapse();
            }
            window.needCollapse = false;
        }
    }
    $('.view-container').children().bind('mouseout', function(e) {
        window.needCollapse = true;
        setTimeout(function() {
            window.tryCollapse();
        }, 100);
    });
    var btn = $('.fr-trigger-btn-up', this.element);
    var view = this.$view;
    btn.bind('click', function() {
        if (!self.isExpanded()) {
            return;
        }
        setTimeout(function() {
            $('.fr-combo-list-item', view).bind('mouseover', function() {
                window.needCollapse = false;
            });
        }, 100);
    });

    Save and preview the effect:

    js-6.gif

    III. Download template

    Attachment List


    Theme: Parameter
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy