랜덤 문의 드립니다.

var Example2 = new (function() {
var $countdown,
$form, // Form used to change the countdown time
incrementTime = 70,
currentTime = 3000,
updateTimer = function() {
$countdown.html(formatTime(currentTime));
if (currentTime == 0) {
Example2.Timer.stop();
timerComplete();
Example2.resetCountdown();
return;
}
currentTime -= incrementTime / 10;
if (currentTime < 0) currentTime = 0;
},
timerComplete = function() {
alert('Example 2: Countdown timer complete!');
},
init = function() {
$countdown = $('#countdown');
Example2.Timer = $.timer(updateTimer, incrementTime, true);
$form = $('#example2form');
$form.bind('submit', function() {
Example2.resetCountdown();
return false;
});
};
this.resetCountdown = function() {
var newTime = parseInt($form.find('input[type=text]').val()) * 100;
if (newTime > 0) {currentTime = newTime;}
this.Timer.stop().once();
};
$(init);
});



currentTime = 3000, 이부분은 1000-3000 사이를 랜덤으로 하고 싶습니다.
어떻게 해야 하나요?
|

댓글 3개

function myRandom(max, min) {
return Math.floor(Math.random()*(max-min)) + min;
}

자바스크립트 랜덤값지정하는 함수입니다~~
var Example2 = new (function() {
var $countdown,
$form, // Form used to change the countdown time
incrementTime = 70,
currentTime = timeRandom(1000,3000),
updateTimer = function() {
$countdown.html(formatTime(currentTime));
if (currentTime == 0) {
Example2.Timer.stop();
timerComplete();
Example2.resetCountdown();
return;
}
currentTime -= incrementTime / 10;
if (currentTime < 0) currentTime = 0;
},
timerComplete = function() {
alert('Example 2: Countdown timer complete!');
},
timerRandem = function(max, min) {
return Math.floor(Math.random()*(max-min)) + min;
},

여기까지 붙여넣어보세요~
var Example2 = new (function() {
var $countdown,
$form, // Form used to change the countdown time
incrementTime = 70,
currentTime = timeRandom(1000,3000),
updateTimer = function() {
$countdown.html(formatTime(currentTime));
if (currentTime == 0) {
Example2.Timer.stop();
timerComplete();
Example2.resetCountdown();
return;
}
currentTime -= incrementTime / 10;
if (currentTime < 0) currentTime = 0;
},
timerComplete = function() {
alert('Example 2: Countdown timer complete!');
},
timerRandem = function(max, min) {
return Math.floor(Math.random()*(max-min)) + min;
},
init = function() {
$countdown = $('#countdown');
Example2.Timer = $.timer(updateTimer, incrementTime, true);
$form = $('#example2form');
$form.bind('submit', function() {
Example2.resetCountdown();
return false;
});
};
this.resetCountdown = function() {
var newTime = parseInt($form.find('input[type=text]').val()) * 100;
if (newTime > 0) {currentTime = newTime;}
this.Timer.stop().once();
};
$(init);
});

이렇게 넣는것이 맞는지요?
카운트 시작을 안합니다.
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기 기존 게시물은 열람만 가능합니다.

+
제목 글쓴이 날짜 조회
12년 전 조회 1,792
12년 전 조회 1,699
12년 전 조회 1,668
12년 전 조회 1,684
12년 전 조회 2,219
12년 전 조회 1,605
12년 전 조회 1,756
12년 전 조회 1,982
12년 전 조회 1,622
12년 전 조회 1,964
12년 전 조회 2,067
12년 전 조회 1,678
12년 전 조회 2,196
12년 전 조회 1,828
12년 전 조회 1,659
12년 전 조회 3,902
12년 전 조회 1,806
12년 전 조회 1,622
12년 전 조회 1,914
12년 전 조회 1,725
🐛 버그신고