Last active
September 22, 2017 06:25
-
-
Save StephanHoyer/640fa4cb29eaa9d45b78 to your computer and use it in GitHub Desktop.
tooltip component
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
'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()); | |
} | |
}; |
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
// 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() | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.