简体   繁体   中英

Showing Tooltipster Tip With Both Focus & Hover

We are utilizing the tooltipster plugin to display a tooltip over an info icon. This works fine on hover. But we also need to have it show if someone tabs to the info icon too.

I can't seem to find any examples of how to enable the popup on both hover AND focus.

This is what existed in this project already:

HTML:

<a href="#"><span class="tooltip">Some handy tooltip text...</span></a>

Javascript:

if ($('.tooltip').length) {
        $('.tooltip').tooltipster({
            theme: '.tooltipster-shadow',
            maxWidth: 220,
            interactive: true,
            functionReady: function () {
                $('html').click(function () {
                    $.fn.tooltipster('hide');
                });
            }
        });
    }

You can use Tooltipster's show method like so:

$('.tooltip').tooltipster().focus(function() {
    $(this).tooltipster('show');
});

Demo

http://iamceege.github.io/tooltipster/#advanced

 $('.tooltip').tooltipster({
            theme: '.tooltipster-shadow',
            trigger: 'custom',
            maxWidth: 220,
            interactive: true,
            functionReady: function () {
                $('html').click(function () {
                    $.fn.tooltipster('hide');
                });
            }.on( 'focus, hover', function() {
               $( this ).tooltipster( 'show' );
            }).on( 'focusout, mouseout', function() {
               $( this ).tooltipster( 'hide' );
            })
        });

I think you are looking for that :

$('.tooltip_hover_n_click').tooltipster({
  delay: 100,
  trigger: 'custom' // disable all by default
}).mouseover(function(){ // show on hover
  $(this).tooltipster('show');
}).blur(function(){ // on click it'll focuses, and will hide only on blur
  $(this).tooltipster('hide');
}).mouseout(function(){ // if user doesnt click, will hide on mouseout
  if(document.activeElement !== this){
    $(this).tooltipster('hide');
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM