랜덤 문의 드립니다.

· 2013-11-25 (월) 17:00:48 · 2112 · 3
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개

2013-11-25 (월) 17:03:35
function myRandom(max, min) {
return Math.floor(Math.random()*(max-min)) + min;
}

자바스크립트 랜덤값지정하는 함수입니다~~
2013-11-25 (월) 17:15:24
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;
},

여기까지 붙여넣어보세요~
2013-11-25 (월) 17:22:28
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 질문답변

66,531건

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

+
제목 글쓴이 날짜 조회
13-11-25 조회 1,841
13-11-25 조회 2,377
13-11-25 조회 1,774
13-11-25 조회 1,927
13-11-25 조회 2,150
13-11-25 조회 1,789
13-11-25 조회 2,113
13-11-25 조회 2,211
13-11-25 조회 1,839
13-11-25 조회 2,381
13-11-25 조회 1,990
13-11-25 조회 1,808
13-11-25 조회 4,081
13-11-25 조회 1,982
13-11-25 조회 1,789
13-11-25 조회 2,066
13-11-25 조회 1,880
13-11-25 조회 1,798
13-11-25 조회 2,626
13-11-25 조회 1,826