Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
added bounce to steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Koo committed Jul 31, 2012
1 parent f2e1b89 commit f54d05d
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 41 deletions.
62 changes: 31 additions & 31 deletions css/animate.css
Expand Up @@ -12,52 +12,52 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
*/

.animated {
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-ms-animation-duration: 1s;
-o-animation-duration: 1s;
animation-duration: 1s;
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-ms-animation-duration: 1s;
-o-animation-duration: 1s;
animation-duration: 1s;
}

.animated.hinge {
-webkit-animation-duration: 2s;
-moz-animation-duration: 2s;
-ms-animation-duration: 2s;
-o-animation-duration: 2s;
animation-duration: 2s;
-webkit-animation-duration: 2s;
-moz-animation-duration: 2s;
-ms-animation-duration: 2s;
-o-animation-duration: 2s;
animation-duration: 2s;
}

@-webkit-keyframes bounce {
0%, 20%, 50%, 80%, 100% {-webkit-transform: translateY(0);}
40% {-webkit-transform: translateY(-30px);}
60% {-webkit-transform: translateY(-15px);}
0%, 20%, 50%, 80%, 100% {-webkit-transform: translateY(0);}
40% {-webkit-transform: translateY(-30px);}
60% {-webkit-transform: translateY(-15px);}
}

@-moz-keyframes bounce {
0%, 20%, 50%, 80%, 100% {-moz-transform: translateY(0);}
40% {-moz-transform: translateY(-30px);}
60% {-moz-transform: translateY(-15px);}
0%, 20%, 50%, 80%, 100% {-moz-transform: translateY(0);}
40% {-moz-transform: translateY(-30px);}
60% {-moz-transform: translateY(-15px);}
}

@-o-keyframes bounce {
0%, 20%, 50%, 80%, 100% {-o-transform: translateY(0);}
40% {-o-transform: translateY(-30px);}
60% {-o-transform: translateY(-15px);}
0%, 20%, 50%, 80%, 100% {-o-transform: translateY(0);}
40% {-o-transform: translateY(-30px);}
60% {-o-transform: translateY(-15px);}
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
40% {transform: translateY(-30px);}
60% {transform: translateY(-15px);}
0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
40% {transform: translateY(-30px);}
60% {transform: translateY(-15px);}
}

.bounce {
-webkit-animation-name: bounce;
-moz-animation-name: bounce;
-o-animation-name: bounce;
animation-name: bounce;
-webkit-animation-name: bounce;
-moz-animation-name: bounce;
-o-animation-name: bounce;
animation-name: bounce;
}
170 changes: 170 additions & 0 deletions css/bounce.less
@@ -0,0 +1,170 @@
/* This bounce file is an extension of http://daneden.me/animate/. Extended to
* add bouncing in different directions.
*/

@rest: 0;
@first: 30px;
@second: 15px;

.animated {
-webkit-animation-fill-mode: both;
-moz-animation-fill-mode: both;
-ms-animation-fill-mode: both;
-o-animation-fill-mode: both;
animation-fill-mode: both;
-webkit-animation-duration: 1s;
-moz-animation-duration: 1s;
-ms-animation-duration: 1s;
-o-animation-duration: 1s;
animation-duration: 1s;
}

.animated.hinge {
-webkit-animation-duration: 2s;
-moz-animation-duration: 2s;
-ms-animation-duration: 2s;
-o-animation-duration: 2s;
animation-duration: 2s;
}

/* =========== */
/* BOUNCE DOWN */
/* =========== */
@-moz-keyframes bounce-down {
0%, 20%, 50%, 80%, 100% { -moz-transform: translateY(@rest); }
40% { -moz-transform:translateY(@first*(-1)); }
60% { -moz-transform:translateY(@second*(-1)); }
}

@-o-keyframes bounce-down {
0%, 20%, 50%, 80%, 100% { -o-transform: translateY(@rest); }
40% { -o-transform:translateY(@first*(-1)); }
60% { -o-transform:translateY(@second*(-1)); }
}

@-webkit-keyframes bounce-down {
0%, 20%, 50%, 80%, 100% { -webkit-transform: translateY(@rest); }
40% { -webkit-transform:translateY(@first*(-1)); }
60% { -webkit-transform:translateY(@second*(-1)); }
}

@keyframes bounce-down {
0%, 20%, 50%, 80%, 100% { transform: translateY(@rest); }
40% { transform:translateY(@first*(-1)); }
60% { transform:translateY(@second*(-1)); }
}

/* ========== */
/* BOUNCE UP */
/* ========== */
@-moz-keyframes bounce-up {
0%, 20%, 50%, 80%, 100% { -moz-transform: translateY(@rest); }
40% { -moz-transform:translateY(@first); }
60% { -moz-transform:translateY(@second); }
}

@-o-keyframes bounce-up {
0%, 20%, 50%, 80%, 100% { -o-transform: translateY(@rest); }
40% { -o-transform:translateY(@first); }
60% { -o-transform:translateY(@second); }
}

@-webkit-keyframes bounce-up {
0%, 20%, 50%, 80%, 100% { -webkit-transform: translateY(@rest); }
40% { -webkit-transform:translateY(@first); }
60% { -webkit-transform:translateY(@second); }
}

@keyframes bounce-up {
0%, 20%, 50%, 80%, 100% { transform: translateY(@rest); }
40% { transform:translateY(@first); }
60% { transform:translateY(@second); }
}

/* =========== */
/* BOUNCE LEFT */
/* =========== */
@-moz-keyframes bounce-left {
0%, 20%, 50%, 80%, 100% { -moz-transform: translateX(@rest); }
40% { -moz-transform:translateX(@first); }
60% { -moz-transform:translateX(@second); }
}

@-o-keyframes bounce-left {
0%, 20%, 50%, 80%, 100% { -o-transform: translateX(@rest); }
40% { -o-transform:translateX(@first); }
60% { -o-transform:translateX(@second); }
}

@-webkit-keyframes bounce-left {
0%, 20%, 50%, 80%, 100% { -webkit-transform: translateX(@rest); }
40% { -webkit-transform:translateX(@first); }
60% { -webkit-transform:translateX(@second); }
}

@keyframes bounce-left {
0%, 20%, 50%, 80%, 100% { transform: translateX(@rest); }
40% { transform:translateX(@first); }
60% { transform:translateX(@second); }
}

/* ============ */
/* BOUNCE RIGHT */
/* ============ */
@-moz-keyframes bounce-right {
0%, 20%, 50%, 80%, 100% { -moz-transform: translateX(@rest); }
40% { -moz-transform:translateX(@first*(-1)); }
60% { -moz-transform:translateX(@second*(-1)); }
}

@-o-keyframes bounce-right {
0%, 20%, 50%, 80%, 100% { -o-transform: translateX(@rest); }
40% { -o-transform:translateX(@first); }
60% { -o-transform:translateX(@second*(-1)); }
}

@-webkit-keyframes bounce-right {
0%, 20%, 50%, 80%, 100% { -webkit-transform: translateX(@rest); }
40% { -webkit-transform:translateX(@first); }
60% { -webkit-transform:translateX(@second*(-1)); }
}

@keyframes bounce-right {
0%, 20%, 50%, 80%, 100% { transform: translateX(@rest); }
40% { transform:translateX(@first); }
60% { transform:translateX(@second*(-1)); }
}

@down-name: bounce-down;
@up-name: bounce-up;
@left-name: bounce-left;
@right-name: bounce-right;

.bounce-down {
-webkit-animation-name: @down-name;
-moz-animation-name: @down-name;
-o-animation-name: @down-name;
animation-name: @down-name;
}

.bounce-up {
-webkit-animation-name: @up-name;
-moz-animation-name: @up-name;
-o-animation-name: @up-name;
animation-name: @up-name;
}

.bounce-left {
-webkit-animation-name: @left-name;
-moz-animation-name: @left-name;
-o-animation-name: @left-name;
animation-name: @left-name;
}

.bounce-right {
-webkit-animation-name: @right-name;
-moz-animation-name: @right-name;
-o-animation-name: @right-name;
animation-name: @right-name;
}

1 change: 1 addition & 0 deletions index.html
Expand Up @@ -3,6 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/hopscotch.less" rel="stylesheet/less"></link>
<link href="css/bounce.less" rel="stylesheet/less"></link>
<script src="js/less-1.3.0.min.js"></script>
<style>
body {
Expand Down
2 changes: 1 addition & 1 deletion js/hopscotch-min.js

Large diffs are not rendered by default.

42 changes: 33 additions & 9 deletions js/hopscotch.js
Expand Up @@ -262,19 +262,22 @@
* target element and the orientation and offset information specified by
* the step JSON.
*/
setPosition = function(bubble, step) {
setPosition = function(bubble, step, bounce) {
var bubbleWidth,
bubbleHeight,
bubblePadding,
boundingRect,
bounceDelay,
bounceDirection,
top,
left,
targetEl = document.getElementById(step.targetId),
el = bubble.element,
arrowEl = bubble.arrowEl,
arrowOffset = utils.getPixelValue(step.arrowOffset);

bubbleWidth = utils.getPixelValue(step.width) || opt.bubbleWidth;
bounce = utils.valOrDefault(bounce, true);
bubbleWidth = utils.getPixelValue(step.width) || opt.bubbleWidth;
bubblePadding = utils.valOrDefault(step.padding, opt.bubblePadding);

// SET POSITION
Expand All @@ -283,18 +286,22 @@
bubbleHeight = el.offsetHeight;
top = (boundingRect.top - bubbleHeight) - opt.arrowWidth;
left = boundingRect.left;
bounceDirection = 'bounce-down';
}
else if (step.orientation === 'bottom') {
top = boundingRect.bottom + opt.arrowWidth;
left = boundingRect.left;
bounceDirection = 'bounce-up';
}
else if (step.orientation === 'left') {
top = boundingRect.top;
left = boundingRect.left - bubbleWidth - 2*bubblePadding - opt.arrowWidth;
bounceDirection = 'bounce-right';
}
else if (step.orientation === 'right') {
top = boundingRect.top;
left = boundingRect.right + opt.arrowWidth;
bounceDirection = 'bounce-left';
}

if (!arrowOffset) {
Expand All @@ -316,15 +323,31 @@
top += utils.getScrollTop();
left += utils.getScrollLeft();

if (!hasCssTransitions && hasJquery && opt.animate) {
$(el).animate({
top: top + 'px',
left: left + 'px'
});
if (opt.animate) {
if (!hasCssTransitions && hasJquery && opt.animate) {
$(el).animate({
top: top + 'px',
left: left + 'px'
});
}
else { // hasCssTransitions || !hasJquery || !opt.animate
el.style.top = top + 'px';
el.style.left = left + 'px';
}
}
else { // hasCssTransitions || !hasJquery || !opt.animate
else {
// Do the bouncing effect
el.style.top = top + 'px';
el.style.left = left + 'px';
bounceDelay = opt.smoothScroll ? opt.scrollDuration : 0;

setTimeout(function() {
utils.addClass(el, bounceDirection);
}, bounceDelay);
// Then remove it
setTimeout(function() {
utils.removeClass(el, bounceDirection);
}, bounceDelay + 2000); // bounce lasts 2 seconds
}
};

Expand All @@ -342,6 +365,7 @@
this.contentEl = document.createElement('p');

el.setAttribute('id', 'hopscotch-bubble');
utils.addClass(el, 'animated');
containerEl.setAttribute('id', 'hopscotch-bubble-container');
this.numberEl.setAttribute('id', 'hopscotch-bubble-number');
containerEl.appendChild(this.titleEl);
Expand All @@ -367,7 +391,7 @@
cooldownActive = true;
winResizeTimeout = setTimeout(function() {
// currStep should not be null
setPosition(self, currStep);
setPosition(self, currStep, false);
cooldownActive = false;
}, 200);
};
Expand Down
14 changes: 14 additions & 0 deletions minify.sh
@@ -0,0 +1,14 @@
#!/bin/bash
echo ""
echo "Minifying files into assets.js..."
echo "================================="
echo "This script uses Google Closure Compiler (http://code.google.com/closure/compiler/) and assumes the location of the compiler is:"
echo "~/workspace/compiler-latest/compiler.jar"
echo ""
echo "INPUT FILES:"
echo "============"
echo "hopscotch.js"

java -jar /Users/gkoo/workspace/yuicompressor-2.4.7/build/yuicompressor-2.4.7.jar --type js js/hopscotch.js > js/hopscotch-min.js

echo "Done minifying..."

0 comments on commit f54d05d

Please sign in to comment.