Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Jquery/Javascript/PHP删除基于滚动的可见通知_Javascript_Php_Jquery_Css_Wordpress - Fatal编程技术网

使用Jquery/Javascript/PHP删除基于滚动的可见通知

使用Jquery/Javascript/PHP删除基于滚动的可见通知,javascript,php,jquery,css,wordpress,Javascript,Php,Jquery,Css,Wordpress,我必须清除/删除基于用户滚动的通知意味着如果用户看到通知,则清除通知。这是一个用于通知的弹出窗口。只有在用户关闭弹出通知窗口后,才应清除/删除所看到的通知。我不熟悉Javascript/jQuery,所以不知道该怎么做。 这是我的密码 <div class="notifications" id="notifications"> <p class="notif" id="1"> First notification <span id='time1'><

我必须清除/删除基于用户滚动的通知意味着如果用户看到通知,则清除通知。这是一个用于通知的弹出窗口。只有在用户关闭弹出通知窗口后,才应清除/删除所看到的通知。我不熟悉Javascript/jQuery,所以不知道该怎么做。 这是我的密码

<div class="notifications" id="notifications">
   <p class="notif" id="1"> First notification <span id='time1'></span></p>
   <p class="notif" id="2"> Second notification <span id='time2'></span></p>
   <p class="notif" id="3"> Third notification <span id='time3'></span></p>
   <p class="notif" id="4"> Fourth notification <span id='time4'></span></p>
   <p class="notif" id="5"> Fifth notification <span id='time5'></span></p>
   <p class="notif" id="6"> Sixth notification <span id='time6'></span></p>
</div>
<script>
   jQuery(function($) {
      $('#notifications').on("scroll", function() {             
         $('.notif').each(function () {
            if( $(this).next().offset() ) {
               console.log("current: " + $(this).offset().top);
               console.log("next: " + $(this).next().offset().top);
               if( $(this).offset().top <= $(this).next().offset().top ) {
                  $(this).find( ".notif" ).css( "color", "red" );
                  //return;
               }
            }
         });
      });
   });
</script>
在控制台日志中,它显示当前和下一个pos值,然后显示错误:TypeError:$..下一个….偏移量。。。是未定义的

在用户关闭弹出通知窗口后,我还不知道如何清除/删除看到的通知。

您需要更改$this.find.notif.css颜色,红色;到 $this.css颜色,红色。这已经是了

jQueryfunction${ $'notifications'.onscroll,函数{ $'.notif'.eachfunction{ 如果$this.next.offset{ console.logcurrent:+$this.offset.top; console.lognext:+$this.next.offset.top;
如果$this.offset.top,请检查$this.next是否存在。最后一个元素没有下一个元素谢谢。我已经编辑了代码。错误消失了,但仍然没有更改字体颜色。谢谢,但此代码会更改所有通知的颜色。当用户向下滚动弹出窗口时,我需要逐个更改通知的颜色。然后,您需要下面更改。if$this.offset.top我按您所说编辑了代码if$this.offset.top谢谢。它不适用于弹出窗口底部的通知。假设,如果有20个通知,它只更改前10个的颜色。我想原因是滚动条更小。另外,为什么$this.offset.top小于50?50是例如,只是随机值。没有特殊意义。您可以根据自己的目的调整值或添加条件。