Skip to content

Instantly share code, notes, and snippets.

@StephanHoyer
Last active September 22, 2017 06:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save StephanHoyer/640fa4cb29eaa9d45b78 to your computer and use it in GitHub Desktop.
Save StephanHoyer/640fa4cb29eaa9d45b78 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()
]);
@StephanHoyer
Copy link
Author

This simple version of the tooltip shows the content always below the element. It also has some issues with scrolled pages.

Improved version is in work.

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