Last active
February 21, 2021 17:13
-
-
Save tayfunerbilen/cb1ca994ab245815dfbe to your computer and use it in GitHub Desktop.
jQuery.timer : Belirtilen dakikadan ve belirtilirse saniyeden geriye saymaya başlar ve bittiğinde callback fonksiyonu çalışır.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<script src="jquery.timer.js"></script> | |
</head> | |
<body> | |
Kalan süre: <span id="timer"></span> | |
<script> | |
$('#timer').timer(5, function(){ | |
alert('sona erdi!'); | |
}); | |
</script> | |
Kalan süre: <span id="timer2"></span> | |
<script> | |
$('#timer2').timer([5, 10], function(){ | |
alert('sona erdi!'); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.timer = function(time, callback){ | |
if ( $.isArray(time) ){ | |
this.minute = time[0]; | |
this.second = time[1]; | |
} else { | |
this.minute = time - 1; | |
this.second = 60; | |
} | |
var self = this, | |
timer = function(){ | |
if ( self.minute == '00' && self.second == '00' ){ | |
clearInterval(self.interval); | |
self.interval = null; | |
callback(); | |
} else { | |
if ( self.second > 0 ) self.second--; | |
else { | |
self.minute -= 1; | |
self.second = 59; | |
} | |
$(self).text((self.minute < 10 ? '0' + self.minute : self.second) + ':' + (self.second < 10 ? '0' + self.second : self.second)); | |
} | |
}; | |
timer(); | |
this.interval = setInterval(timer, 1000); | |
} |
farklı tarayıcılarda aynı anda çalışmasını nasıl sağlayabilirim
farklı tarayıcılarda aynı anda çalışmasını nasıl sağlayabilirim
bunun için socket'le eşitleme yapmak gerekir, yani time'ın ortak olması gerekir, socket'i araştırabilirsiniz.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
eyvallah