简体   繁体   English

对于移动Webkit,如何在触摸/拖动时使水平菜单栏滚动?

[英]For mobile webkit, how can I make the horizontal menu bar scrollable when you touch/drag it?

Let's say I'm on the standard iPhone 4. 假设我使用的是标准的iPhone 4。

My menu bar is 2000px in width. 我的菜单栏的宽度为2000px。 When the user touches and holds on the menu div, he can move his finger left/right, and the menu bar will move. 当用户触摸并按住菜单div时,他可以左右移动手指,菜单栏将移动。 This allows the user to browse all of the menu's items using his finger. 这允许用户使用他的手指浏览所有菜单项。 (Scrolling left/right) (向左/向右滚动)

How can I make that in javascript/jquery? 如何在javascript / jquery中做到这一点?

It's like the Google Images webview (go there on your phone). 就像Google图片网络视图(在手机上)。 You're able to swipe left and right to navigate each image. 您可以左右滑动来浏览每个图像。

Except...I want it to be a menu bar, with no "snapping". 除了...我希望它成为一个菜单栏,没有“捕捉”。

Here's a very very basic example. 这是一个非常非常基本的示例。 It should get you moving in the right direction though. 它应该使您朝正确的方向前进。

$('body').bind({
    'touchmove': function(e){

        $('.menu_bar').css({
            'left': e.originalEvent.touches[0].pageX
        });

    }
});

To get where you're headed you'll need to also store the touchstart coordinates, the .menu_bar start position and then use a bit of math to move the bar relative to it's position rather than just snapping to the finger position each time like the example above will do. 要到达目的地,您还需要存储touchstart坐标,.menu_bar起始位置,然后使用一些数学运算来将条形相对于其位置移动,而不是每次都像只是将其移动到手指位置上面的例子可以。

Hope that helps :) 希望有帮助:)

I'm still a little confused by the question but I believe the answer is just to use 我仍然对该问题感到困惑,但我相信答案仅是用于

    -webkit-overflow-scrolling: touch;

This will work for iOS5 devices and give you a small scroll bar when active (ie when scrolling) 这将适用于iOS5设备,并在活动时(即滚动时)为您提供一个小的滚动条

Otherwise you could try this plugin: http://cubiq.org/iscroll-4 否则,您可以尝试使用此插件: http : //cubiq.org/iscroll-4

Or: http://chris-barr.com/index.php/entry/scrolling_a_overflowauto_element_on_a_touch_screen_device/ (which is multi-device) 或者: http : //chris-barr.com/index.php/entry/scrolling_a_overflowauto_element_on_a_touch_screen_device/ (多设备)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM