Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add swiss railway clock pause #3

Merged
merged 1 commit into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

<script src="lib/svg.min.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/svg.easing.min.js" type="text/javascript" charset="utf-8"></script>
<script src="svg.clock.min.js" type="text/javascript" charset="utf-8"></script>
<script src="svg.clock.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
SVG('canvas').clock('100%').start()
</script>

</html>
</html>
18 changes: 11 additions & 7 deletions svg.clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ SVG.extend(SVG.Clock, {

/* ensure duration */
if (duration == null)
duration = 300
duration = 1000

/* set all pointers */
this
.setHours(time.getHours(), time.getMinutes())
.setMinutes(time.getMinutes(), duration)
.setSeconds(time.getSeconds(), duration)
.setSeconds(time.getSeconds(), duration, true)

return this
}
Expand Down Expand Up @@ -165,28 +165,32 @@ SVG.extend(SVG.Clock, {
return this
}
// Set second
, setSeconds: function(seconds, duration) {
, setSeconds: function(seconds, duration, pause) {
/* store seconds */
this.time.seconds = seconds

/* register a full circle */
if (seconds == 0)
if (pause && seconds>=59) {
this.full.seconds++

seconds = 0
} else if (pause) {
seconds = this.time.seconds * (60/58.0)
}

/* calculate rotation */
var deg = this.full.seconds * 360 + 360 / 60 * seconds

/* animate if duration is given */
if (duration)
this.seconds
.animate(duration, SVG.easing.elastic)
.animate(duration, this.linear)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should probably make this optional (linear only when 'pause' is true).

.rotate(deg, 50, 50)
else
this.seconds
.rotate(deg, 50, 50)

return this
}
, linear: function(pos) { return pos }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After svgdotjs/svg.easing.js#6 we don't need this.


})

Expand Down