Skip to content

Instantly share code, notes, and snippets.

@Bondifrench
Forked from StephanHoyer/tooltip.js
Created September 22, 2017 06:25
Show Gist options
  • Save Bondifrench/10598f2e98fed2aa59ff39113c028564 to your computer and use it in GitHub Desktop.
Save Bondifrench/10598f2e98fed2aa59ff39113c028564 to your computer and use it in GitHub Desktop.
tooltip component
'use strict';
function noop(){}
var contentView = noop;
var elPos = { left: 0, bottom: 0};
var tooltip = {
show: function(content, options) {
return function(event) {
elPos = event.currentTarget.getBoundingClientRect();
contentView = function() {
return content;
};
};
},
hide: function() {
contentView = noop;
},
view: function() {
return m('.tooltip', {
style: 'top: ' + elPos.bottom + 'px; left: ' + elPos.left + 'px; position: absolute'
}, contentView());
}
};
// in the view where you want to use the tooltip
m('div', {
onmouseover: tooltip.show('hurray')
onmouseout: tooltip.hide
})
// somewhere in a baseView
m('main', [
// other stuff
tooltip.view()
]);
@Bondifrench
Copy link
Author

This was done with previous version of Mithril

@Bondifrench
Copy link
Author

Bondifrench commented Sep 27, 2017

Flems demo here

Inspiration from this tutorial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment