Scrollable div on iPhone without using 2 fingers?

前端 未结 7 1758
南方客
南方客 2021-01-01 06:10

I\'ve got a UIWebView embedded in my iPhone app, and I\'d like to keep a locked header and footer DIV on the page at all times, with a scrollable center DIV.

I know

7条回答
  •  借酒劲吻你
    2021-01-01 06:39

    Is this what you're looking for? Open this link on your iPhone device or simulator.

    The index.html file has three div elements for "header", "container" and "footer" directly under the body, while all the work is done in the fixed.js file. The document is fixed in place by canceling the normal action for the "touchmove" event:

        // Disable flick events
        disableScrollOnBody : function() {
            document.body.addEventListener("touchmove", function(e) {
                e.preventDefault();
            }, false);
        },
    

    Then, a lot of work goes into creating event listeners for the "touchstart", "touchmove" and "touchend" events which are attached to the "content" div under "container". The logic boils down to simply moving the "content" div up and down.

    This solution is 100% HTML/CSS/JavaScript, however there is some WebKit proprietary CSS and JavaScript which may limit portability. It may take a bit of tweaking to work on another mobile device but this would be a good proof-of-concept to start from.

    I did not create this awesome sample project, I'm merely bringing it to the community's attention. For more information and a link to the zipped project, read Richard "Doctyper" Herrara's entire post on Fixed positioning in Mobile Safari.

提交回复
热议问题