Skip to content

Commit

Permalink
tooltip calculation cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
acburst committed Jul 16, 2016
1 parent 2c7072a commit b9e279b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 45 deletions.
10 changes: 5 additions & 5 deletions bin/materialize.css
Original file line number Diff line number Diff line change
Expand Up @@ -4817,7 +4817,6 @@ small {
left: 0;
top: 0;
pointer-events: none;
will-change: top, left;
}

.backdrop {
Expand All @@ -4826,12 +4825,13 @@ small {
display: none;
height: 7px;
width: 14px;
border-radius: 0 0 14px 14px;
border-radius: 0 0 50% 50%;
background-color: #323232;
z-index: -1;
-webkit-transform-origin: 50% 10%;
transform-origin: 50% 10%;
will-change: transform, opacity;
-webkit-transform-origin: 50% 0%;
transform-origin: 50% 0%;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}

.btn, .btn-large,
Expand Down
6 changes: 3 additions & 3 deletions bin/materialize.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion css/ghpages-materialize.css

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions js/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
// Create backdrop
backdrop = $('<div class="backdrop"></div>');
backdrop.appendTo(tooltip);
backdrop.css({ top: 0, left:0 });
return tooltip;
};
tooltipEl = renderTooltipEl();
Expand All @@ -91,7 +90,8 @@
var tooltipWidth = tooltipEl.outerWidth();
var tooltipVerticalMovement = '0px';
var tooltipHorizontalMovement = '0px';
var scale_factor = 8;
var scaleXFactor = 8;
var scaleYFactor = 8;
var targetTop, targetLeft, newCoordinates;

if (tooltipPosition === "top") {
Expand All @@ -102,8 +102,10 @@

tooltipVerticalMovement = '-10px';
backdrop.css({
bottom: 0,
left: 0,
borderRadius: '14px 14px 0 0',
transformOrigin: '50% 90%',
transformOrigin: '50% 100%',
marginTop: tooltipHeight,
marginLeft: (tooltipWidth/2) - (backdrop.width()/2)
});
Expand All @@ -116,6 +118,8 @@

tooltipHorizontalMovement = '-10px';
backdrop.css({
top: '-7px',
right: 0,
width: '14px',
height: '14px',
borderRadius: '14px 0 0 14px',
Expand All @@ -132,6 +136,8 @@

tooltipHorizontalMovement = '+10px';
backdrop.css({
top: '-7px',
left: 0,
width: '14px',
height: '14px',
borderRadius: '0 14px 14px 0',
Expand All @@ -147,6 +153,8 @@
newCoordinates = repositionWithinScreen(targetLeft, targetTop, tooltipWidth, tooltipHeight);
tooltipVerticalMovement = '+10px';
backdrop.css({
top: 0,
left: 0,
marginLeft: (tooltipWidth/2) - (backdrop.width()/2)
});
}
Expand All @@ -158,21 +166,14 @@
});

// Calculate Scale to fill
scale_factor = tooltipWidth / 8;
if (scale_factor < 8) {
scale_factor = 8;
}
if (tooltipPosition === "right" || tooltipPosition === "left") {
scale_factor = tooltipWidth / 10;
if (scale_factor < 6)
scale_factor = 6;
}
scaleXFactor = Math.SQRT2 * tooltipWidth / parseInt(backdrop.css('width'));
scaleYFactor = Math.SQRT2 * tooltipHeight / parseInt(backdrop.css('height'));

tooltipEl.velocity({ marginTop: tooltipVerticalMovement, marginLeft: tooltipHorizontalMovement}, { duration: 350, queue: false })
.velocity({opacity: 1}, {duration: 300, delay: 50, queue: false});
backdrop.css({ display: 'block' })
.velocity({opacity:1},{duration: 55, delay: 0, queue: false})
.velocity({scale: scale_factor}, {duration: 300, delay: 0, queue: false, easing: 'easeInOutQuad'});
.velocity({scaleX: scaleXFactor, scaleY: scaleYFactor}, {duration: 300, delay: 0, queue: false, easing: 'easeInOutQuad'});
};

timeoutRef = setTimeout(showTooltip, tooltipDelay); // End Interval
Expand All @@ -189,7 +190,7 @@
if (started !== true) {
tooltipEl.velocity({
opacity: 0, marginTop: 0, marginLeft: 0}, { duration: 225, queue: false});
backdrop.velocity({opacity: 0, scale: 1}, {
backdrop.velocity({opacity: 0, scaleX: 1, scaleY: 1}, {
duration:225,
queue: false,
complete: function(){
Expand Down
42 changes: 20 additions & 22 deletions sass/components/_tooltip.scss
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
.material-tooltip {
padding: 10px 8px;
font-size: 1rem;
z-index: 2000;
background-color: transparent;
border-radius: 2px;
color: #fff;
min-height: 36px;
line-height: 120%;
opacity: 0;
display: none;
position: absolute;
text-align: center;
max-width: calc(100% - 4px);
overflow: hidden;
left:0;
top:0;
pointer-events: none;
will-change: top, left;
padding: 10px 8px;
font-size: 1rem;
z-index: 2000;
background-color: transparent;
border-radius: 2px;
color: #fff;
min-height: 36px;
line-height: 120%;
opacity: 0;
display: none;
position: absolute;
text-align: center;
max-width: calc(100% - 4px);
overflow: hidden;
left: 0;
top: 0;
pointer-events: none;
}

.backdrop {
Expand All @@ -25,10 +24,9 @@
display: none;
height: 7px;
width: 14px;
border-radius: 0 0 14px 14px;
border-radius: 0 0 50% 50%;
background-color: #323232;
z-index: -1;
transform-origin: 50% 10%;

will-change: transform, opacity;
transform-origin: 50% 0%;
transform: translate3d(0,0,0);
}

0 comments on commit b9e279b

Please sign in to comment.