Comments (2)
No problem! You're calculating the hours correctly, but you need to compensate the minutes, just like with the seconds. Here's what the format function should look like (not tested):
config.format = function(v) {
var sec = parseInt(v);
var min = Math.floor(sec / 60);
var hour = Math.floor(min / 60);
sec -= min * 60;
min -= hour * 60;
return hour + ':' + (min < 10? "0" + min : min) + ':' + (sec < 10 ? "0" + sec : sec);
};
I'm not sure about rotating an icon - if nothing else, there's probably something in the HTML5/CSS3 standards that would allow you to create some sort of canvas. I'm on mobile at the moment so I can't really check. Good luck!
from expressworks.
@owenfromcanada
thank you so much !! it works and look great XD
// initialize static data
var targetTime = undefined;
var targetDelta = undefined;
var intervalId = undefined;
var reset = true;
var onSession = true;
// main timer setup function
function setupTimerDisplay() {
var config = {};
var value = 0;
if (onSession === true) {
value = $('#hour').val() * 3600;
$('#timer-display').val(value);
config.max = value;
config.format = function(v) {
var sec = parseInt(v); //秒
var min = Math.floor(sec / 60); //分
var hour = Math.floor(min / 60); //小時
sec -= min * 60;
min -= hour *60;
return (hour < 10 ? '0' + hour : hour) + ':' + (min < 10 ? '0' + min : min) + ':' + (sec < 10 ? '0' + sec : sec);
};
}
$('#timer-display').trigger('configure', config);
$('#timer-display').val(value);
$('#timer-display').trigger('change');
}
//if knob failed to load, fall back to regular input display
if (jQuery().knob) {
$('#timer-display').knob({
'min': 0,
'max': 100,
'width': 250,
'height': 250,
'rotation': 'anticlockwise',
'fgColor': '#D7F4FF',
'bgColor': '#D8D8D8',
'readOnly': true,
'thickness': 0.1,
'draw': function () {
var degInRad = 2*this.cv*Math.PI/10800;//10800
console.log(this.cv)
$('.pointer').css({
top: this.xy - this.radius*Math.cos(degInRad),
right: this.xy + this.radius*Math.sin(degInRad),
transform : 'rotate(' + (10800 - this.cv)*360/10800 +'deg)',
});
}
});
}
// periodic timer function
function updateTimer() {
var now = new Date();
targetDelta = targetTime.getTime() - now.getTime();
if (targetDelta > 0) {
var sec = Math.ceil(targetDelta / 1000);
if (!onSession) sec = breakLength - sec;
$('#timer-display').val(sec);
$('#timer-display').trigger('change');
}
else {
targetTime = new Date(Date.now() + targetDelta);
setupTimerDisplay();
}
}
// initialize timer display
targetDelta = $('#hour').val() * 3600000;
setupTimerDisplay();
// button click events
$('#cmd-reset').click(function() {
targetDelta = $('#hour').val() * 3600000;
if (intervalId) {
window.clearInterval(intervalId);
intervalId = undefined;
}
reset = true;
onSession = true;
$('#cmd-pause').addClass('hidden');
$('#cmd-go').removeClass('hidden');
setupTimerDisplay();
return false;
});
$('#cmd-go').click(function() {
targetTime = new Date(Date.now() + targetDelta);
intervalId = window.setInterval(updateTimer, 200);
reset = false;
$('#cmd-go').addClass('hidden');
$('#cmd-pause').removeClass('hidden');
return false;
});
$('#cmd-pause').click(function() {
window.clearInterval(intervalId);
intervalId = undefined;
$('#cmd-pause').addClass('hidden');
$('#cmd-go').removeClass('hidden');
return false;
});
from expressworks.
Related Issues (20)
- Jade renamed to Pug HOT 2
- Jade challenge Error. HOT 2
- Cannot Verify Stylish CSS HOT 2
- Static HOT 1
- Exercise 4/8 "Good Old Form" does not run verification HOT 1
- PARAM PAM PAM and port to listening on HOT 1
- JSON me: Official solution fails HOT 1
- Good old form. I can't understand routes HOT 2
- Crypto Hashes are coming different HOT 4
- Cannot pass stylish-css challenge
- Stylish CSS "run" doesn't pass but "verify" does
- Pug isn't sensed, even when it's installed
- STATIC | missed path and passed in the verification
- Upstream issue re: Pug for Exercise 3
- Install expressworks failed with npm
- All paths to resources missing
- Stylish CSS hangs on run and verify
- Bodyparser is deprecated
- Incorrect Links HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expressworks.