-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathsample088.html
23 lines (22 loc) · 1.13 KB
/
sample088.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html lang="en">
<body>
<div id="counter1"></div>
<div id="counter2"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script> (function ($) {
$.fn.count = function (customOptions) {
// Create new option, extend object with defaultOptoins and customOptions
var options = $.extend({}, $.fn.count.defaultOptions, customOptions);
return this.each(function () {
var $this = $(this); // Sets the counter start number to the default option value
// or to custom option value if it is passed to the plugin
$this.text(options.startCount + '');
var myInterval = window.setInterval(function () { var currentCount = parseFloat($this.text()); var newCount = currentCount + 1; $this.text(newCount + ''); }, 1000);
});
}; $.fn.count.defaultOptions = { startCount: 100 };
})(jQuery); // Passing a custom option overrides default
jQuery('#counter1, #counter2').count({ startCount: 500 });
</script>
</body>
</html>