Created
March 14, 2018 22:04
-
-
Save jasonday/e18e7966d73572de7e55d528f42060e8 to your computer and use it in GitHub Desktop.
Bootstrap accessible tooltip: includes consideration for low dexterity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Dependencies: | |
* - Bootstrap: https://getbootstrap.com/docs/4.0/components/tooltips/ | |
* - hoverIntent.js: https://github.com/tristen/hoverintent | |
* | |
* Demo: https://codepen.io/jasonday/pen/vRGXMv | |
* | |
*/ | |
$(document).ready(function() { | |
// set bootstrap tooltip to manual | |
$('[data-toggle="tooltip"]').tooltip({ | |
trigger: "manual" | |
}); | |
// trigger tooltip with hoverIntent | |
$('[data-toggle="tooltip"]').hoverIntent({ | |
over: function() { | |
$(this).tooltip("show"); | |
}, | |
out: function() {} | |
}); | |
// trigger tooltip on focus | |
$('[data-toggle="tooltip"]').on("focus", function() { | |
$(this).tooltip("show"); | |
}); | |
// hide tooltip on interaction with other elements | |
$(document).on("focus keydown click", function(e) { | |
if (!$(e.target).is('[data-toggle="tooltip"]')) { | |
$(".tooltip").tooltip("hide"); | |
} | |
}); | |
// trigger tooltip on focus | |
$('[data-toggle="tooltip"]').on("focus", function() { | |
$(this).tooltip("show"); | |
}); | |
// hide tooltip on interaction with other elements | |
$(document).on("focus keydown click", function(e) { | |
if (!$(e.target).is('[data-toggle="tooltip"]')) { | |
$(".tooltip").tooltip("hide"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment