在用户关闭一次后,我如何将隐藏的特定ID隐藏的特定ID保留为DIV(范围内的上拉)



我的网站底部有一个横幅,该横幅在7秒钟后逐渐消失,并且用户有一个关闭按钮供用户淡出。

我要实现的是用户只需要每次访问一次即可。当他们点击博客(从一个帖子到另一帖子)时,我不想在通知中打扰他们。

我拥有的是:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
const showPullup = localStorage.getItem('showPullup');
if(showPullup === 'false'){
  $('#pullup').hide();
}
$(function() {
  $("#pullup").delay(7000).fadeIn(400);
});
    $('#pullup .close').bind('click',function(){
        $(this).parent().fadeOut(200);
        localStorage.setItem('showPullup', 'false');
    });
</script>

您可以看到,我不知道我在做什么,因此,如果有人可以在用户浏览我们的网站时帮助我隐藏此东西,我将非常感激。

我会添加以下CSS

#pullup
{
  display: none;
}

并使用此JavaScript

$(function() {
    const showPullup = localStorage.getItem('showPullup'); // Get the item from local storage
    if(showPullup !== 'false'){ // If it doesn't equal false, i.e. its not been opened before show the showPullup
        $("#pullup").css('display', 'block'); // Set display: block
    }
    // On click close, set local storage to false
    $('#pullup .close').bind('click',function(){
            $(this).parent().fadeOut(200);
            localStorage.setItem('showPullup', 'false');
    });
});

最新更新