溢出时移动滚动方向检测:隐藏页面

时间:2015-11-10 09:55:12

标签: javascript jquery jquery-mobile mobile scroll

我想检测手机上的滚动/触摸方向。对于桌面版,我使用.on('DOMMouseScroll').('mousewheel'),但这不适用于手机。 页面正文为overflow: hidden; 有人知道如何检测这个吗?

1 个答案:

答案 0 :(得分:0)

看来我和你的情况一样。

由于我需要进行大量研究才能将所有内容放在一起,所以我在这里发布:

private RelativeLayout batteryContainer;
    private LinearLayout batteryLeftSide;
    private LinearLayout batteryRightSide;

    public void drawBattery(){
            handler.post(new Runnable() {
                @Override
                public void run() {

                    //Контейнер всієї батарейки
                    batteryContainer = new RelativeLayout(activity);
                    RelativeLayout.LayoutParams batteryContainerParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                    batteryContainerParams.setMargins((int) convertDpToPixel(containerMarginLeft), (int) convertDpToPixel(containerMarginTop), (int) convertDpToPixel(containerMarginRight), (int) convertDpToPixel(containerMarginBottom));
                    if(layoutBelow != null){
                        batteryContainerParams.addRule(RelativeLayout.BELOW, layoutBelow.getId());
                    }
                    if(layoutAbove != null){
                        batteryContainerParams.addRule(RelativeLayout.ABOVE, layoutAbove.getId());
                    }
                    batteryContainer.setLayoutParams(batteryContainerParams);
                    batteryContainer.setBackgroundColor(Color.parseColor("#505050"));
                    batteryContainer.setId(containerId);

                    int leftWidth = 0;
                    int rightWidth = 0;

                    //Ліва частина батарейки
                    batteryLeftSide = new LinearLayout(activity);
                    batteryLeftSide.setOrientation(LinearLayout.HORIZONTAL);
                    RelativeLayout.LayoutParams batteryLeftSideParams = new RelativeLayout.LayoutParams((int)convertDpToPixel(leftWidth), (int)convertDpToPixel(sideHeight));
                    batteryLeftSideParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                    batteryLeftSide.setLayoutParams(batteryLeftSideParams);
                    batteryLeftSide.setBackgroundColor(Color.parseColor("#900000"));
                    batteryLeftSide.setId(leftSideId);

                    //Права частина батарейки
                    batteryRightSide = new LinearLayout(activity);
                    batteryRightSide.setOrientation(LinearLayout.HORIZONTAL);
                    RelativeLayout.LayoutParams batteryRightSideParams = new RelativeLayout.LayoutParams((int)convertDpToPixel(rightWidth), (int)convertDpToPixel(sideHeight));
                    batteryRightSideParams.addRule(RelativeLayout.RIGHT_OF, batteryLeftSide.getId());
                    batteryRightSide.setLayoutParams(batteryRightSideParams);
                    batteryRightSide.setBackgroundColor(Color.parseColor("#009900"));
                    batteryRightSide.setId(rightSideId);

                    //Додамо праві та ліві сторони в контейнер
                    batteryContainer.addView(batteryLeftSide);
                    batteryContainer.addView(batteryRightSide);
                    //Додамо контейнер в кореневий Layout на активності
                    rootLayout.addView(batteryContainer);

                    //Обчислення яка сторона батарейки займе 50%
                    ViewTreeObserver observer = rootLayout.getViewTreeObserver();
                    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                            int batteryContainerWidth = batteryContainer.getMeasuredWidth();
                            int halfPlace = batteryContainerWidth * 50 / 100;
                            trustFromMe = halfPlace;
                            if(trustToMe > trustFromMe){
                                batteryLeftSide.getLayoutParams().width = halfPlace;
                            }
                            if(trustToMe < trustFromMe){
                                batteryRightSide.getLayoutParams().width = halfPlace;
                            }
                            if(trustToMe == trustFromMe){
                                batteryLeftSide.getLayoutParams().width = halfPlace;
                                batteryRightSide.getLayoutParams().width = halfPlace;
                            }
                        }
                    });
                    //but width not change

                }
            });
        }