kel1mc,
запятая в конце 27 строки у вас в 1 посте очень опасная
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script>
(function($) {
$.fn.countdown = function (date, options) {
options = $.extend({
lang: {
years: ['год', 'года', 'лет'],
months: ['месяц', 'месяца', 'месяцев'],
days: ['день', 'дня', 'дней'],
hours: ['час', 'часа', 'часов'],
minutes: ['минута', 'минуты', 'минут'],
seconds: ['секунда', 'секунды', 'секунд'],
plurar: function(n) {
return (n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2);
}
},
prefix: "Осталось: ",
finish: "Всё"
}, options);
var timeDifference = function(begin, end) {
if (end < begin) {
return false;
}
var diff = {
// seconds: [end.getSeconds() - begin.getSeconds(), 60],
minutes: [end.getMinutes() - begin.getMinutes(), 60],
hours: [end.getHours() - begin.getHours(), 24],
days: [Math.round((date.getTime() - (new Date()).getTime())/(24*60*60*1000)),0]
//days: [end.getDate() - begin.getDate(), new Date(begin.getYear(), begin.getMonth() + 1, 0).getDate()],
//months: [end.getMonth() - begin.getMonth(), 12]//,
// years: [end.getYear() - begin.getYear(), 0]
};
var result = new Array();
var flag = false;
for (i in diff) {
if (flag) {
diff[i][0]--;
flag = false;
}
if (diff[i][0] < 0) {
flag = true;
diff[i][0] += diff[i][1];
}
if (diff[i][0]<10) diff[i][0]="0"+diff[i][0];
result.push('<span>' + diff[i][0] + ' <span>' + options.lang[i][options.lang.plurar(diff[i][0])]+'</span></span>');
}
return result.reverse().join(' ');
};
var elem = $(this);
var timeUpdate = function () {
var s = timeDifference(new Date(), date);
if (s.length) {
elem.html('<div class="timer-title">'+options.prefix+'</div>' + s);
} else {
clearInterval(timer);
elem.html('<div class="timer-title">'+options.finish+'</div>');
}
};
timeUpdate();
var timer = setInterval(timeUpdate, 1000);
};
})(jQuery);
$(document).ready(function () {
var date = new Date((new Date).getFullYear()+1, 0, 1, 0, 0, 0, 0 )
$('#new_year').countdown(date);
});
</script>
</head>
<body>
<div id="new_year">2014</div>
</body>
</html>
|