How do you close the Iris colour picker when you click away from it?

前端 未结 3 1758
走了就别回头了
走了就别回头了 2021-01-13 06:54

I\'m using the iris colour picker in a Wordpress plugin. I can get it to display and then show the clicked value in the associated input just fine, however there is a proble

相关标签:
3条回答
  • 2021-01-13 07:02

    You can try something like this:

    jQuery(document).ready(function ($) {    
        $('.colour-picker').iris();    
        $(document).click(function (e) {
            if (!$(e.target).is(".colour-picker, .iris-picker, .iris-picker-inner")) {
                $('.colour-picker').iris('hide');
                return false;
            }
        });
        $('.colour-picker').click(function (event) {
            $('.colour-picker').iris('hide');
            $(this).iris('show');
            return false;
        });
    });
    

    Updated fiddle

    0 讨论(0)
  • 2021-01-13 07:21

    you can try like below

    $('input:not(.colour-picker)').iris('hide');
    
    0 讨论(0)
  • 2021-01-13 07:25

    For what it's worth, you don't need to call iris directly. As of 3.5, The WordPress core defines a wrapper method called wpColorPicker(), that implements iris with some additional functionality:

    http://make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5/

    This wrapper takes care of all the hiding and showing of the picker for you, and keeps track of individual instances.

    If you're building a WP plugin, it's probably better to use their wrapper, as they will be adding new features to it in the future. Plus, if they decide to go with another library other than iris, your plugin code will likely break. The wrapper will prevent that from happening.

    0 讨论(0)
提交回复
热议问题