Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Redraw via requestAnimationFrame if element has transition / animatio…
Browse files Browse the repository at this point in the history
…n on it.
  • Loading branch information
Worie committed Dec 19, 2016
1 parent 1714336 commit 2796fef
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/LiveDevelopment/Agents/RemoteFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ function RemoteFunctions(config) {

var experimental = config.experimental;
var lastKeepAliveTime = Date.now();
var req, timeout;
var animateHighlight = function (time) {
if(req) {
cancelAnimationFrame(req);
clearTimeout(timeout);
}
req = requestAnimationFrame(redrawHighlights);

timeout = setTimeout(function () {
cancelAnimationFrame(req);
req = null;
}, time * 1000);
};

/**
* @type {DOMEditHandler}
Expand Down Expand Up @@ -234,11 +247,18 @@ function RemoteFunctions(config) {
}
return false;
},

_makeHighlightDiv: function (element, doAnimation) {
var elementBounds = element.getBoundingClientRect(),
highlight = window.document.createElement("div"),
styles = window.getComputedStyle(element);
var transitionDuration = parseFloat(styles.getPropertyValue('transition-duration'));

var animationDuration = parseFloat(styles.getPropertyValue('animation-duration'));

if (transitionDuration)
animateHighlight(transitionDuration);
if (animationDuration)
animateHighlight(animationDuration);

// Don't highlight elements with 0 width & height
if (elementBounds.width === 0 && elementBounds.height === 0) {
Expand Down Expand Up @@ -433,7 +453,8 @@ function RemoteFunctions(config) {
"border-width": "1px",
"border-color": "#00a2ff",
"box-shadow": "0 0 1px #fff",
"box-sizing": "border-box"
"box-sizing": "border-box",
"transform": styles.getPropertyValue('transform')
};

var mergedStyles = Object.assign({}, stylesToSet, config.remoteHighlight.stylesToSet);
Expand Down

0 comments on commit 2796fef

Please sign in to comment.