Skip to content

Commit b0c5644

Browse files
committed
"goto now accepts duration parameter"
1 parent 9d99c03 commit b0c5644

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ VERSION HISTORY
4545
- you can give it a number of step you want to go to: `impress().goto(7)`
4646
- or its id: `impress().goto("the-best-slide-ever")`
4747
- of course DOM element is still acceptable: `impress().goto( document.getElementById("overview") )`
48+
* and if it's not enough, `goto()` also accepts second parameter to define the transition duration in ms, for example
49+
`impress().goto("make-it-quick", 300)` or `impress().goto("now", 0)`
50+
4851

4952
### 0.4.1 ([browse](http://github.com/bartaz/impress.js/tree/0.4.1), [zip](http://github.com/bartaz/impress.js/zipball/0.4.1), [tar](http://github.com/bartaz/impress.js/tarball/0.4.1))
5053

index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ <h1>impress.js<sup>*</sup></h1>
340340
`api.init()` - initializes the presentation,
341341
`api.next()` - moves to next step of the presentation,
342342
`api.prev()` - moves to previous step of the presentation,
343-
`api.goto( idx | id | element )` - moves the presentation to the step given by its index number,
344-
id or the DOM element.
343+
`api.goto( idx | id | element, [duration] )` - moves the presentation to the step given by its index number
344+
id or the DOM element; second parameter can be used to define duration of the transition in ms,
345+
but it's optional - if not provided default transition duration for the presentation will be used.
345346
346347
You can also simply call `impress()` again to get the API, so `impress().next()` is also allowed.
347348
Don't worry, it wont initialize the presentation again.

js/impress.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@
365365
return (step && step.id && stepsData["impress-" + step.id]) ? step : null;
366366
};
367367

368-
var goto = function ( el, force ) {
368+
var goto = function ( el, duration ) {
369369

370-
if ( !initialized || !(el = getStep(el)) || (el === activeStep && !force) ) {
371-
// selected element is not defined as step or is already active
370+
if ( !initialized || !(el = getStep(el)) ) {
371+
// presentation not initialized or given element is not a step
372372
return false;
373373
}
374374

@@ -409,12 +409,10 @@
409409
// check if the transition is zooming in or not
410410
var zoomin = target.scale >= currentState.scale;
411411

412-
// if presentation starts (nothing is active yet)
413-
// don't animate (set duration to 0)
414-
var duration = (activeStep) ? config.transitionDuration : 0,
415-
delay = (config.transitionDuration / 2);
412+
duration = toNumber(duration, config.transitionDuration);
413+
var delay = (duration / 2);
416414

417-
if (force) {
415+
if (el === activeStep) {
418416
windowScale = computeWindowScale(config);
419417
}
420418

@@ -486,23 +484,28 @@
486484
root.addEventListener("impress-init", function(){
487485
// HASH CHANGE
488486

487+
var lastHash = "";
488+
489489
// `#/step-id` is used instead of `#step-id` to prevent default browser
490490
// scrolling to element in hash
491491
//
492492
// and it has to be set after animation finishes, because in Chrome it
493493
// causes transtion being laggy
494494
// BUG: http://code.google.com/p/chromium/issues/detail?id=62820
495495
root.addEventListener("impress-step-enter", function (event) {
496-
window.location.hash = "#/" + event.target.id;
496+
window.location.hash = lastHash = "#/" + event.target.id;
497497
}, false);
498498

499499
window.addEventListener("hashchange", function () {
500-
goto( getElementFromUrl() );
500+
// don't go twice to same element
501+
if (window.location.hash !== lastHash) {
502+
goto( getElementFromUrl() );
503+
}
501504
}, false);
502505

503506
// START
504507
// by selecting step defined in url or first step of the presentation
505-
goto(getElementFromUrl() || steps[0]);
508+
goto(getElementFromUrl() || steps[0], 0);
506509
}, false);
507510

508511
body.classList.add("impress-disabled");
@@ -633,7 +636,7 @@
633636
// rescale presentation when window is resized
634637
window.addEventListener("resize", throttle(function () {
635638
// force going to active step again, to trigger rescaling
636-
api.goto( document.querySelector(".active"), true );
639+
api.goto( document.querySelector(".active"), 500 );
637640
}, 250), false);
638641

639642
}, false);

0 commit comments

Comments
 (0)