smooth reset of auto-slide progress, fix overlapping repaint calls
This commit is contained in:
1 parent
2736945385
commit
d761adf002
2 files changed
+47
-25
No files matched your search
+45
-23
@@ -2847,18 +2847,26 @@ var Reveal = (function(){
|
||||
*/
|
||||
function Playback( container, progressCheck ) {
|
||||
|
||||
this.size = 50;
|
||||
// Cosmetics
|
||||
this.diameter = 50;
|
||||
this.thickness = 3;
|
||||
|
||||
// Flags if we are currently playing
|
||||
this.playing = false;
|
||||
|
||||
// Current progress on a 0-1 range
|
||||
this.progress = 0;
|
||||
|
||||
// Used to loop the animation smoothly
|
||||
this.progressOffset = 1;
|
||||
|
||||
this.container = container;
|
||||
this.progressCheck = progressCheck;
|
||||
|
||||
this.canvas = document.createElement( 'canvas' );
|
||||
this.canvas.className = 'playback';
|
||||
this.canvas.width = this.size;
|
||||
this.canvas.height = this.size;
|
||||
this.canvas.width = this.diameter;
|
||||
this.canvas.height = this.diameter;
|
||||
this.context = this.canvas.getContext( '2d' );
|
||||
|
||||
this.container.appendChild( this.canvas );
|
||||
@@ -2869,21 +2877,32 @@ var Reveal = (function(){
|
||||
|
||||
Playback.prototype.setPlaying = function( value ) {
|
||||
|
||||
var wasPlaying = this.playing;
|
||||
|
||||
this.playing = value;
|
||||
|
||||
// Render instantly
|
||||
this.render();
|
||||
|
||||
// Start repainting if we're playing
|
||||
if( this.playing ) {
|
||||
// Start repainting if we weren't already
|
||||
if( !wasPlaying && this.playing ) {
|
||||
this.animate();
|
||||
}
|
||||
else {
|
||||
this.render();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Playback.prototype.animate = function() {
|
||||
|
||||
var progressBefore = this.progress;
|
||||
|
||||
this.progress = this.progressCheck();
|
||||
|
||||
// When we loop, offset the progress so that it eases
|
||||
// smoothly rather than immediately resetting
|
||||
if( progressBefore > 0.8 && this.progress < 0.2 ) {
|
||||
this.progressOffset = this.progress;
|
||||
}
|
||||
|
||||
this.render();
|
||||
|
||||
if( this.playing ) {
|
||||
@@ -2897,19 +2916,20 @@ var Reveal = (function(){
|
||||
*/
|
||||
Playback.prototype.render = function() {
|
||||
|
||||
var progress = this.playing ? this.progress : 0;
|
||||
var progress = this.playing ? this.progress : 0,
|
||||
radius = ( this.diameter / 2 ) - this.thickness,
|
||||
x = this.diameter / 2,
|
||||
y = this.diameter / 2,
|
||||
iconSize = 14;
|
||||
|
||||
var radius = ( this.size / 2 ) - this.thickness,
|
||||
x = this.size / 2,
|
||||
y = this.size / 2;
|
||||
// Ease towards 1
|
||||
this.progressOffset += ( 1 - this.progressOffset ) * 0.1;
|
||||
|
||||
var iconSize = 14;
|
||||
|
||||
var startAngle = - Math.PI / 2;
|
||||
var endAngle = startAngle + ( progress * ( Math.PI * 2 ) );
|
||||
var endAngle = ( - Math.PI / 2 ) + ( progress * ( Math.PI * 2 ) );
|
||||
var startAngle = ( - Math.PI / 2 ) + ( this.progressOffset * ( Math.PI * 2 ) );
|
||||
|
||||
this.context.save();
|
||||
this.context.clearRect( 0, 0, this.size, this.size );
|
||||
this.context.clearRect( 0, 0, this.diameter, this.diameter );
|
||||
|
||||
// Solid background color
|
||||
this.context.beginPath();
|
||||
@@ -2924,12 +2944,14 @@ var Reveal = (function(){
|
||||
this.context.strokeStyle = '#666';
|
||||
this.context.stroke();
|
||||
|
||||
// Draw progress on top of track
|
||||
this.context.beginPath();
|
||||
this.context.arc( x, y, radius, startAngle, endAngle, false );
|
||||
this.context.lineWidth = this.thickness;
|
||||
this.context.strokeStyle = '#fff';
|
||||
this.context.stroke();
|
||||
if( this.playing ) {
|
||||
// Draw progress on top of track
|
||||
this.context.beginPath();
|
||||
this.context.arc( x, y, radius, startAngle, endAngle, false );
|
||||
this.context.lineWidth = this.thickness;
|
||||
this.context.strokeStyle = '#fff';
|
||||
this.context.stroke();
|
||||
}
|
||||
|
||||
this.context.translate( x - ( iconSize / 2 ), y - ( iconSize / 2 ) );
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
/*!
|
||||
* reveal.js 2.6.0-dev (2013-10-18, 09:13)
|
||||
* reveal.js 2.6.0-dev (2013-10-19, 09:34)
|
||||
* http://lab.hakim.se/reveal-js
|
||||
* MIT licensed
|
||||
*
|
||||
* Copyright (C) 2013 Hakim El Hattab, http://hakim.se
|
||||
*/
|
||||
var Reveal=function(){"use strict";function a(a){return b(),_b.transforms2d||_b.transforms3d?(window.addEventListener("load",C,!1),l(Wb,a),l(Wb,Reveal.getQueryHash()),s(),c(),void 0):(document.body.setAttribute("class","no-transforms"),void 0)}function b(){_b.transforms3d="WebkitPerspective"in document.body.style||"MozPerspective"in document.body.style||"msPerspective"in document.body.style||"OPerspective"in document.body.style||"perspective"in document.body.style,_b.transforms2d="WebkitTransform"in document.body.style||"MozTransform"in document.body.style||"msTransform"in document.body.style||"OTransform"in document.body.style||"transform"in document.body.style,_b.requestAnimationFrameMethod=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,_b.requestAnimationFrame="function"==typeof _b.requestAnimationFrameMethod,_b.canvas=!!document.createElement("canvas").getContext,Qb=navigator.userAgent.match(/(iphone|ipod|android)/gi)}function c(){function a(){c.length&&head.js.apply(null,c),d()}for(var b=[],c=[],e=0,f=Wb.dependencies.length;f>e;e++){var g=Wb.dependencies[e];(!g.condition||g.condition())&&(g.async?c.push(g.src):b.push(g.src),"function"==typeof g.callback&&head.ready(g.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],g.callback))}b.length?(head.ready(a),head.js.apply(null,b)):a()}function d(){f(),e(),i(),ab(),setTimeout(function(){$b.slides.classList.remove("no-transition"),Xb=!0,u("ready",{indexh:Mb,indexv:Nb,currentSlide:Pb})},1)}function e(){var a=m(document.querySelectorAll(Tb));a.forEach(function(a){var b=m(a.querySelectorAll("section"));b.forEach(function(a,b){b>0&&a.classList.add("future")})})}function f(){$b.theme=document.querySelector("#theme"),$b.wrapper=document.querySelector(".reveal"),$b.slides=document.querySelector(".reveal .slides"),$b.slides.classList.add("no-transition"),$b.background=g($b.wrapper,"div","backgrounds",null),$b.progress=g($b.wrapper,"div","progress","<span></span>"),$b.progressbar=$b.progress.querySelector("span"),g($b.wrapper,"aside","controls",'<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>'),g($b.wrapper,"div","state-background",null),g($b.wrapper,"div","pause-overlay",null),$b.controls=document.querySelector(".reveal .controls"),$b.controlsLeft=m(document.querySelectorAll(".navigate-left")),$b.controlsRight=m(document.querySelectorAll(".navigate-right")),$b.controlsUp=m(document.querySelectorAll(".navigate-up")),$b.controlsDown=m(document.querySelectorAll(".navigate-down")),$b.controlsPrev=m(document.querySelectorAll(".navigate-prev")),$b.controlsNext=m(document.querySelectorAll(".navigate-next"))}function g(a,b,c,d){var e=a.querySelector("."+c);return e||(e=document.createElement(b),e.classList.add(c),null!==d&&(e.innerHTML=d),a.appendChild(e)),e}function h(){function a(a,b){var c={background:a.getAttribute("data-background"),backgroundSize:a.getAttribute("data-background-size"),backgroundImage:a.getAttribute("data-background-image"),backgroundColor:a.getAttribute("data-background-color"),backgroundRepeat:a.getAttribute("data-background-repeat"),backgroundPosition:a.getAttribute("data-background-position"),backgroundTransition:a.getAttribute("data-background-transition")},d=document.createElement("div");return d.className="slide-background",c.background&&(/^(http|file|\/\/)/gi.test(c.background)||/\.(svg|png|jpg|jpeg|gif|bmp)$/gi.test(c.background)?d.style.backgroundImage="url("+c.background+")":d.style.background=c.background),c.backgroundSize&&(d.style.backgroundSize=c.backgroundSize),c.backgroundImage&&(d.style.backgroundImage='url("'+c.backgroundImage+'")'),c.backgroundColor&&(d.style.backgroundColor=c.backgroundColor),c.backgroundRepeat&&(d.style.backgroundRepeat=c.backgroundRepeat),c.backgroundPosition&&(d.style.backgroundPosition=c.backgroundPosition),c.backgroundTransition&&d.setAttribute("data-background-transition",c.backgroundTransition),b.appendChild(d),d}r()&&document.body.classList.add("print-pdf"),$b.background.innerHTML="",$b.background.classList.add("no-transition"),m(document.querySelectorAll(Tb)).forEach(function(b){var c;c=r()?a(b,b):a(b,$b.background),m(b.querySelectorAll("section")).forEach(function(b){r()?a(b,b):a(b,c)})}),Wb.parallaxBackgroundImage?($b.background.style.backgroundImage='url("'+Wb.parallaxBackgroundImage+'")',$b.background.style.backgroundSize=Wb.parallaxBackgroundSize,setTimeout(function(){$b.wrapper.classList.add("has-parallax-background")},1)):($b.background.style.backgroundImage="",$b.wrapper.classList.remove("has-parallax-background"))}function i(a){var b=document.querySelectorAll(Sb).length;if($b.wrapper.classList.remove(Wb.transition),"object"==typeof a&&l(Wb,a),_b.transforms3d===!1&&(Wb.transition="linear"),$b.wrapper.classList.add(Wb.transition),$b.wrapper.setAttribute("data-transition-speed",Wb.transitionSpeed),$b.wrapper.setAttribute("data-background-transition",Wb.backgroundTransitionLine truncated
|
||||
var Reveal=function(){"use strict";function a(a){return b(),_b.transforms2d||_b.transforms3d?(window.addEventListener("load",C,!1),l(Wb,a),l(Wb,Reveal.getQueryHash()),s(),c(),void 0):(document.body.setAttribute("class","no-transforms"),void 0)}function b(){_b.transforms3d="WebkitPerspective"in document.body.style||"MozPerspective"in document.body.style||"msPerspective"in document.body.style||"OPerspective"in document.body.style||"perspective"in document.body.style,_b.transforms2d="WebkitTransform"in document.body.style||"MozTransform"in document.body.style||"msTransform"in document.body.style||"OTransform"in document.body.style||"transform"in document.body.style,_b.requestAnimationFrameMethod=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame,_b.requestAnimationFrame="function"==typeof _b.requestAnimationFrameMethod,_b.canvas=!!document.createElement("canvas").getContext,Qb=navigator.userAgent.match(/(iphone|ipod|android)/gi)}function c(){function a(){c.length&&head.js.apply(null,c),d()}for(var b=[],c=[],e=0,f=Wb.dependencies.length;f>e;e++){var g=Wb.dependencies[e];(!g.condition||g.condition())&&(g.async?c.push(g.src):b.push(g.src),"function"==typeof g.callback&&head.ready(g.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],g.callback))}b.length?(head.ready(a),head.js.apply(null,b)):a()}function d(){f(),e(),i(),ab(),setTimeout(function(){$b.slides.classList.remove("no-transition"),Xb=!0,u("ready",{indexh:Mb,indexv:Nb,currentSlide:Pb})},1)}function e(){var a=m(document.querySelectorAll(Tb));a.forEach(function(a){var b=m(a.querySelectorAll("section"));b.forEach(function(a,b){b>0&&a.classList.add("future")})})}function f(){$b.theme=document.querySelector("#theme"),$b.wrapper=document.querySelector(".reveal"),$b.slides=document.querySelector(".reveal .slides"),$b.slides.classList.add("no-transition"),$b.background=g($b.wrapper,"div","backgrounds",null),$b.progress=g($b.wrapper,"div","progress","<span></span>"),$b.progressbar=$b.progress.querySelector("span"),g($b.wrapper,"aside","controls",'<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>'),g($b.wrapper,"div","state-background",null),g($b.wrapper,"div","pause-overlay",null),$b.controls=document.querySelector(".reveal .controls"),$b.controlsLeft=m(document.querySelectorAll(".navigate-left")),$b.controlsRight=m(document.querySelectorAll(".navigate-right")),$b.controlsUp=m(document.querySelectorAll(".navigate-up")),$b.controlsDown=m(document.querySelectorAll(".navigate-down")),$b.controlsPrev=m(document.querySelectorAll(".navigate-prev")),$b.controlsNext=m(document.querySelectorAll(".navigate-next"))}function g(a,b,c,d){var e=a.querySelector("."+c);return e||(e=document.createElement(b),e.classList.add(c),null!==d&&(e.innerHTML=d),a.appendChild(e)),e}function h(){function a(a,b){var c={background:a.getAttribute("data-background"),backgroundSize:a.getAttribute("data-background-size"),backgroundImage:a.getAttribute("data-background-image"),backgroundColor:a.getAttribute("data-background-color"),backgroundRepeat:a.getAttribute("data-background-repeat"),backgroundPosition:a.getAttribute("data-background-position"),backgroundTransition:a.getAttribute("data-background-transition")},d=document.createElement("div");return d.className="slide-background",c.background&&(/^(http|file|\/\/)/gi.test(c.background)||/\.(svg|png|jpg|jpeg|gif|bmp)$/gi.test(c.background)?d.style.backgroundImage="url("+c.background+")":d.style.background=c.background),c.backgroundSize&&(d.style.backgroundSize=c.backgroundSize),c.backgroundImage&&(d.style.backgroundImage='url("'+c.backgroundImage+'")'),c.backgroundColor&&(d.style.backgroundColor=c.backgroundColor),c.backgroundRepeat&&(d.style.backgroundRepeat=c.backgroundRepeat),c.backgroundPosition&&(d.style.backgroundPosition=c.backgroundPosition),c.backgroundTransition&&d.setAttribute("data-background-transition",c.backgroundTransition),b.appendChild(d),d}r()&&document.body.classList.add("print-pdf"),$b.background.innerHTML="",$b.background.classList.add("no-transition"),m(document.querySelectorAll(Tb)).forEach(function(b){var c;c=r()?a(b,b):a(b,$b.background),m(b.querySelectorAll("section")).forEach(function(b){r()?a(b,b):a(b,c)})}),Wb.parallaxBackgroundImage?($b.background.style.backgroundImage='url("'+Wb.parallaxBackgroundImage+'")',$b.background.style.backgroundSize=Wb.parallaxBackgroundSize,setTimeout(function(){$b.wrapper.classList.add("has-parallax-background")},1)):($b.background.style.backgroundImage="",$b.wrapper.classList.remove("has-parallax-background"))}function i(a){var b=document.querySelectorAll(Sb).length;if($b.wrapper.classList.remove(Wb.transition),"object"==typeof a&&l(Wb,a),_b.transforms3d===!1&&(Wb.transition="linear"),$b.wrapper.classList.add(Wb.transition),$b.wrapper.setAttribute("data-transition-speed",Wb.transitionSpeed),$b.wrapper.setAttribute("data-background-transition",Wb.backgroundTransitionLine truncated
|
||||
Reference in new issue
Block a user