JS Button color change according to mouse hover

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

    1.1 Problem

    When the mouse is hovering over the widget for the first time, it changes from the initial red color to blue, and then becomes grey when the mouse is moved away. Afterwards, it turns blue every time the mouse is hovered on it.

    The effect is as follows:

    1.gif


    1.2 Solution

    Monitor widget events, and trigger different effects under different monitoring events.

    Note: The mobile devices does not support this function

    II. Example

    2.1 Template preparation

    Create a new workbook, right-click cell B2, select [widget Settings], and select [Button widget]

    2.png


    2.2 Add event

    Add an [event after initialization], the JS is as follows:

    var el = this.element.children();
    // get current widget
    el.css('background', 'red');
    // default is red
    el.hover(function(e) {
    // monitor mouse event
            $(this).css('background', 'blue');
            // turn blue on hover
    }, function(e) {
            $(this).css('background', '#abc');
            // turn grey on moving away
    });

    3.png


    2.3 Preview effect

    Save the template and select [Data Entry Preview] to achieve the effect as shown in the figure below:

    4.gif


    III. Download template

    Attachment List


    Theme: Data Entry
    • 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