$(function(){ var rand = ''; var json2 = ''; var data = $.cookie("fcookie"); //data = ''; if(!data) { $.ajax({ url : '/js/kuji.php?sp=1', type : "get", data : '', async : false, success: function(d) { var json = eval('(' + d + ')'); rand = json.rand; json2 = d; } }); $('body').append('

おもくじを引く

'); }else{ rand = data; var str_style = (rand > 0 && rand < 10) ? 'id="result' + rand + '"' : 'style="background-image: url(/kuji/data/' + rand + ')"'; $('body').append('
結果
'); } var kuji = $('[data-remodal-id=omikuji]').remodal({hashTracking:false,closeOnOutsideClick:true}); $(document).on("click",".popkuji", function(e){ e.preventDefault(); kuji.open(); }); $(document).on("click",".result", function(){ kuji.close(); }); $("#start p").on('click', 'span', function(e) { e.preventDefault(); fortune(); setCookie(); }); function fortune(){ $('#kujiBox').html('

おみくじ

'); setTimeout(function() { // $('#kujiBox').html('
結果
'); var json = eval('(' + json2 + ')'); $('#kujiBox').html('
結果
'); }, 2000); } function setCookie (){ var clifetime = new Date(); clifetime.setDate(clifetime.getDate()+1); clifetime.setHours(0); clifetime.setMinutes(0); clifetime.setSeconds(0); // clifetime.setTime(clifetime.getTime()+(24*60*60*1000));//24時間 $.cookie('fcookie', rand, { expires: clifetime , path: '/'}); $.cookie('fcookie2', json2, { expires: clifetime , path: '/'}); } });