设置jQuery Modal Window Cookie

Uskro

我正在尝试向此jQuery添加cookie,以作为我正在工作的网站的模式窗口。要打开的div是#scrolltriggered的,结束ID是#closebox。我已经链接了jQuery Cookie(在这里),但是GitHUB页面上建议的cookie行没有任何作用。尽管我了解HTML和CSS的方式,但我是jQuery的新手,所有代码都是我从其他人的脚本中拼凑而成的零碎代码,因此,如果还有其他更简便的方法可以将此模式窗口存储为X位数,几天,我也将不胜感激。谢谢!

$.cookie('renovatpop', '1', { expires: 7, path: '/' });

idleTime = 0;
$(document).ready(function(){
    $limit = 5;
        function timerIncrement() {
            idleTime = idleTime + 1;
            if (idleTime > $limit) { 
                $('#scrolltriggered ').show();
                idleTime = 0;
            }
        }
        // Increment the idle time counter every second.
        var idleInterval = setInterval(timerIncrement, 1000); // 1 second

        // Zero the idle timer on mouse movement.
        $(this).mousemove(function (e) {
            idleTime = 0;
        });
        $(this).keypress(function (e) {
            idleTime = 0;
        });

        $('#closebox').click(function() {
            $('#scrolltriggered').hide();
            $limit = 9999;
        });

        $.cookie('renovatpop', '1', { expires: 7, path: '/' });
});
Uskro

我回答了我自己的问题。

脚本:jQuery(1.10+)和jQuery cookie(我建议在本地使用)。

<!-- jQuery library script -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- SCROLL POP UP -->
<script src="jquery.cookie.js"></script>
<script src="script.js"></script>

和以下脚本:

idleTime = 0;
$(document).ready(function(){
        if ($.cookie('modal_shown') == null) {
        $.cookie('modal_shown', 'yes', { expires: 7, path: '/' });
    $limit = 7;
        function timerIncrement() {

            idleTime = idleTime + 1;
            if (idleTime > $limit) {
                $('#scrolltriggered ').show();
                idleTime = 0;
            }
        }
        // Increment the idle time counter every second.
        var idleInterval = setInterval(timerIncrement, 1000); // 1 second

        // Zero the idle timer on mouse movement.
        $(this).mousemove(function (e) {
            idleTime = 0;
        });
        $(this).keypress(function (e) {
            idleTime = 0;
        });

        $('#closebox').click(function() {
            $('#scrolltriggered').hide();
            $limit = 9999;
        });
        }
    });

该脚本将执行以下操作:创建一个模态窗口函数,该函数将在网站完全加载到网页上之后的7秒钟弹出,并创建一个名为“ modal_shown”的cookie,该cookie在创建后将存在7天。

如果要修改模式出现的秒数,请修改值:$ limit = 7

如果要修改cookie在访问者系统中的天数,请修改值:expires:7

!important-记住要在您的服务器上进行测试,它将无法在本地运行。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章