gpt4 book ai didi

javascript - 从倒计时器中删除天数和小时数

转载 作者:行者123 更新时间:2023-12-03 23:04:16 25 4
gpt4 key购买 nike

我正在使用此 jQuery 文件中的倒计时器,但我想从中删除天数和小时数,以便它只显示分钟和秒。谁能帮我吗?这些数字是从 png 文件中显示的,该文件在显示倒计时时会创建翻转板效果。

jQuery.fn.countdown = function(userOptions)
{
// Default options
var options = {
stepTime: 60,
// startTime and format MUST follow the same format.
// also you cannot specify a format unordered (e.g. hh:ss:mm is wrong)
format: "dd:hh:mm:ss",
startTime: "01:12:32:55",
digitImages: 6,
digitWidth: 53,
digitHeight: 77,
timerEnd: function(){},
image: "digits.png"
};
var digits = [], interval;

// Draw digits in given container
var createDigits = function(where)
{
var c = 0;
// Iterate each startTime digit, if it is not a digit
// we'll asume that it's a separator
for (var i = 0; i < options.startTime.length; i++)
{
if (parseInt(options.startTime[i]) >= 0)
{
elem = $('<div id="cnt_' + i + '" class="cntDigit" />').css({
height: options.digitHeight * options.digitImages * 10,
float: 'left', background: 'url(\'' + options.image + '\')',
width: options.digitWidth});
digits.push(elem);
margin(c, -((parseInt(options.startTime[i]) * options.digitHeight *
options.digitImages)));
digits[c].__max = 9;
// Add max digits, for example, first digit of minutes (mm) has
// a max of 5. Conditional max is used when the left digit has reach
// the max. For example second "hours" digit has a conditional max of 4
switch (options.format[i]) {
case 'h':
digits[c].__max = (c % 2 == 0) ? 2: 9;
if (c % 2 == 0)
digits[c].__condmax = 4;
break;
case 'd':
digits[c].__max = 9;
break;
case 'm':
case 's':
digits[c].__max = (c % 2 == 0) ? 5: 9;
}
++c;
}
else
elem = $('<div class="cntSeparator"/>').css({float: 'left'})
.text(options.startTime[i]);

where.append(elem)
}
};

// Set or get element margin
var margin = function(elem, val)
{
if (val !== undefined)
return digits[elem].css({'marginTop': val + 'px'});

return parseInt(digits[elem].css('marginTop').replace('px', ''));
};

// Makes the movement. This is done by "digitImages" steps.
var moveStep = function(elem)
{
digits[elem]._digitInitial = -(digits[elem].__max * options.digitHeight * options.digitImages);
return function _move() {
mtop = margin(elem) + options.digitHeight;
if (mtop == options.digitHeight) {
margin(elem, digits[elem]._digitInitial);
if (elem > 0) moveStep(elem - 1)();
else
{
clearInterval(interval);
for (var i=0; i < digits.length; i++) margin(i, 0);
options.timerEnd();
return;
}
if ((elem > 0) && (digits[elem].__condmax !== undefined) &&
(digits[elem - 1]._digitInitial == margin(elem - 1)))
margin(elem, -(digits[elem].__condmax * options.digitHeight * options.digitImages));
return;
}

margin(elem, mtop);
if (margin(elem) / options.digitHeight % options.digitImages != 0)
setTimeout(_move, options.stepTime);

if (mtop == 0) digits[elem].__ismax = true;
}
};

$.extend(options, userOptions);
this.css({height: options.digitHeight, overflow: 'hidden'});
createDigits(this);
interval = setInterval(moveStep(digits.length - 1), 1000);
};
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Countdown that doesn't sucks</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.countdown.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
$('#counter').countdown({
image: 'img/digits.png',
startTime: '00:00:05:00'
});

});
</script>

<style type="text/css">
br { clear: both; }
.cntSeparator {
font-size: 54px;
margin: 10px 7px;
color: #000;
}
.desc { margin: 7px 3px; }
.desc div {
float: left;
font-family: Arial;
width: 70px;
margin-right: 65px;
font-size: 13px;
font-weight: bold;
color: #000;
}
</style>
</head>
<body>

最佳答案

更改开始时间和格式以使用 mm:ss 格式对我有用。如果您需要隐藏数字,同时仍然需要倒计时天和小时,则可以使用 style=overflow:hidden;左:-50%

jQuery.fn.countdown = function(userOptions)
{
// Default options
var options = {
stepTime: 60,
// startTime and format MUST follow the same format.
// also you cannot specify a format unordered (e.g. hh:ss:mm is wrong)
format: "dd:hh:mm:ss",
startTime: "01:12:32:55",
digitImages: 6,
digitWidth: 53,
digitHeight: 77,
timerEnd: function(){},
image: "digits.png"
};
var digits = [], interval;

// Draw digits in given container
var createDigits = function(where)
{
var c = 0;
// Iterate each startTime digit, if it is not a digit
// we'll asume that it's a separator
for (var i = 0; i < options.startTime.length; i++)
{
if (parseInt(options.startTime[i]) >= 0)
{
elem = $('<div id="cnt_' + i + '" class="cntDigit" />').css({
height: options.digitHeight * options.digitImages * 10,
float: 'left', background: 'url(\'' + options.image + '\')',
width: options.digitWidth});
digits.push(elem);
margin(c, -((parseInt(options.startTime[i]) * options.digitHeight *
options.digitImages)));
digits[c].__max = 9;
// Add max digits, for example, first digit of minutes (mm) has
// a max of 5. Conditional max is used when the left digit has reach
// the max. For example second "hours" digit has a conditional max of 4
switch (options.format[i]) {
case 'h':
digits[c].__max = (c % 2 == 0) ? 2: 9;
if (c % 2 == 0)
digits[c].__condmax = 4;
break;
case 'd':
digits[c].__max = 9;
break;
case 'm':
case 's':
digits[c].__max = (c % 2 == 0) ? 5: 9;
}
++c;
}
else
elem = $('<div class="cntSeparator"/>').css({float: 'left'})
.text(options.startTime[i]);

where.append(elem)
}
};

// Set or get element margin
var margin = function(elem, val)
{
if (val !== undefined)
return digits[elem].css({'marginTop': val + 'px'});

return parseInt(digits[elem].css('marginTop').replace('px', ''));
};

// Makes the movement. This is done by "digitImages" steps.
var moveStep = function(elem)
{
digits[elem]._digitInitial = -(digits[elem].__max * options.digitHeight * options.digitImages);
return function _move() {
mtop = margin(elem) + options.digitHeight;
if (mtop == options.digitHeight) {
margin(elem, digits[elem]._digitInitial);
if (elem > 0) moveStep(elem - 1)();
else
{
clearInterval(interval);
for (var i=0; i < digits.length; i++) margin(i, 0);
options.timerEnd();
return;
}
if ((elem > 0) && (digits[elem].__condmax !== undefined) &&
(digits[elem - 1]._digitInitial == margin(elem - 1)))
margin(elem, -(digits[elem].__condmax * options.digitHeight * options.digitImages));
return;
}

margin(elem, mtop);
if (margin(elem) / options.digitHeight % options.digitImages != 0)
setTimeout(_move, options.stepTime);

if (mtop == 0) digits[elem].__ismax = true;
}
};

$.extend(options, userOptions);
this.css({height: options.digitHeight, overflow: 'hidden'});
createDigits(this);
interval = setInterval(moveStep(digits.length - 1), 1000);
};
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Countdown that doesn't sucks</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.countdown/2.2.0/jquery.countdown.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
$('#counter').countdown({
image: 'https://i.ibb.co/5hvG3DY/digits.png',
startTime: '05:00',
format: "mm:ss"
});

});
</script>

<style type="text/css">
br { clear: both; }
.cntSeparator {
font-size: 54px;
margin: 10px 7px;
color: #000;
}
.desc { margin: 7px 3px; }
.desc div {
float: left;
font-family: Arial;
width: 70px;
margin-right: 65px;
font-size: 13px;
font-weight: bold;
color: #000;
}
</style>
</head>
<body>
<div id="counter"></div>
</body>
</html>

关于javascript - 从倒计时器中删除天数和小时数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61961217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com