1
我有一個微調遊戲,我正在建設。一旦微調停止旋轉,我想要一個問題表單出現。單擊旋轉後是否有延遲表單啓動的方法?如何在調用事件後延遲某個功能的執行?
/*WHEEL SPIN FUNCTION*/
$('#spin').click(function() {
//add 1 every click
clicks++;
/*multiply the degree by number of clicks
generate random number between 1 - 360,
then add to the new degree*/
var newDegree = degree * clicks;
var extraDegree = Math.floor(Math.random() * (360 - 1 + 1)) + 1;
totalDegree = newDegree + extraDegree;
/*let's make the spin btn to tilt every
time the edge of the section hits
the indicator*/
$('#wheel .sec').each(function() {
var t = $(this);
var noY = 0;
var c = 0;
var n = 700;
var interval = setInterval(function() {
c++;
if (c === n) {
clearInterval(interval);
}
var aoY = t.offset().top;
$("#txt").html(aoY);
console.log(aoY);
/*23.7 is the minimum offset number that
each section can get, in a 30 angle degree.
So, if the offset reaches 23.7, then we know
that it has a 30 degree angle and therefore,
exactly aligned with the spin btn*/
if (aoY < 23.89) {
console.log('<<<<<<<<');
$('#spin').addClass('spin');
setTimeout(function() {
$('#spin').removeClass('spin');
}, 100);
}
}, 10);
$('#inner-wheel').css({
'transform': 'rotate(' + totalDegree + 'deg)'
});
noY = t.offset().top;
});
//have form appear once the spinner stops
showForm();
});
function showForm() {
if (aoY > 0) {
$("#formWrapper").show();
};
}
感謝您的回答......但它似乎沒有解決問題。這是一個鏈接到我的git集線器的所有代碼。 https://github.com/omaracrystal/gschool-trivia – Crystal
@xgrioux - 您的資料庫是最新的。當我下載並運行示例時,我收到了一個關於aoY未被定義的重複錯誤。 –
@xgrioux更新了我對新建議的回答。讓我知道它是否讓你走上正軌。 –