jQuery UI のモーダルと sessionStorage を調べます。
探しているものの例を次に示します。
function showHelpModal()
{
// Open the dialog and reset the timer
$('#mymodal').dialog('open');
timeoutStarted = false;
}
var t; // Timeout variable
var timeout = 1500; // Timeout in milliseconds
var fakeSessionStorage = {}; // The fake sessionStorage, don't use this in your real code
$(document).ready(function()
{
// Initialize the dialog
$('#mymodal').dialog(
{
autoOpen: false,
height: 500,
width: 500,
modal: true,
buttons: {
"Don't remind me": function()
{
fakeSessionStorage.stopReminding = true;
$(this).dialog('close');
},
"Yes, please": function()
{
$(this).dialog('close');
}
}
});
// Set default reminder value
if(!fakeSessionStorage.stopReminding)
fakeSessionStorage.stopReminding = false;
// On scroll...
$(document).scroll(function()
{
// If the user doesn't want to be reminded, return false
if(fakeSessionStorage.stopReminding)
{
console.log("Will not remind again");
return false;
}
// Start the timer and prevent it from firing while busy
timeoutStarted = true;
clearTimeout(t);
t = setTimeout(showHelpModal, timeout);
});
});
そしてJSfiddleの実例
sessionStorage は JSfiddle では機能しないことに注意してください。そのため、それfakeSessionStorage
をカバーするために呼び出されたオブジェクトを使用しました。
また、sessionStorage は Internet Explorer 7 以前では機能しません。
[編集]
間違ったフィドルがリンクされていたので修正しました。
[編集 2]
そこに変数
を持つtimeoutStarted
ことは明らかに問題でした。必要なことだと思っていましたが、良いことよりも悪いことをしていました.