JS マウスを離れると自動でドロップダウンボックスを隠す

  • 作成者:ayuan0625
  • 編集回数:12次
  • 最終更新:ayuan0625 于 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: FineReport カスタム開発
    既に最初
    既に最後
    • いいね
    • 良くない
    • 閲覧しただけ