在移动Safari中创建这种效果?

发布于 2024-12-19 23:18:26 字数 635 浏览 4 评论 0原文

我想在移动游猎中创建这种效果。 http://jqueryfordesigners.com/demo/header-slide.html

我正在使用iScroll 4。我想将 iScroll 与此示例混合。

http://jsfiddle.net/tdQmQ/3/ (这是我到目前为止所拥有的,使用鼠标像触摸事件一样轻拂)

标题不应该位于滚动区域吗?如果有人能指出我正确的方向,那就太好了。

最大的问题是锁定 iScroll 的滚动事件,我不知道如何。

谢谢

编辑:我终于构建了我想要的东西, http://jsfiddle.net/tdQmQ/25 - 仍然需要修复 z-index,以便标题显示在克隆框上方。

EDIT2:实际上我最终更改了库以公开其 x 和 y 位置,而不是对 dom 元素进行间隔轮询。如果您不介意破解该库,效果会更好。

I want to create this effect in mobile safari. http://jqueryfordesigners.com/demo/header-slide.html

I'm using iScroll 4. I want to mix iScroll with this example.

http://jsfiddle.net/tdQmQ/3/ (here is what i have so far, use the mouse to flick like a touch event)

Should headers not be in the scroll area? If any one can point me in the right direction that would be great.

The biggest problem is latching onto scroll events of iScroll, i dont know how.

Thanks

EDIT: I finally built what I was looking for, http://jsfiddle.net/tdQmQ/25 - still need to fix the z-index so headers show above the clone box though.

EDIT2: I actually ended up changing the library to expose its x and y positions, instead of doing the interval polling on the dom element. Works much better if you don't mind hacking the lib.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我最亲爱的 2024-12-26 23:18:26

繁荣:http://jsfiddle.net/jasper/tdQmQ/11/ (更新为包括 touchend 事件以及 mouseup

JS--

var scroller = new iScroll('scroll',{snap:'.header'}),
    $headers = $('.header:not(.fixed)'),
    prefix   = $('#content')[0].style[0].replace('transition-property', '');

$('#content').on('mouseup touchend', function () {
    setTimeout(function () {
        var y  = $('#content').css(prefix + 'transform').replace(')', '').split(',')[5],
            of = {index : 0, offset : 10000};

        $headers.each(function (index, obj) {
            var tmp = Math.abs($(this).position().top + parseInt(y));
            //console.log($(this).position().top + ' + ' + parseInt(y) + ' = ' + tmp);
            if (tmp < of.offset) {
                of.offset = tmp;
                of.index  = index;
            }
        });
        //console.log(of.index + ' = ' + of.offset);
        $('#head').text($headers.eq(of.index).text());
    }, 500);
});

HTML--

<div id="iphonewrap">
    <div class="header fixed" id="head">head1</div>
    <div id="scroll">
        <ul id="content">
            <li>
                <div class="header">head1</div>
                <div class="body">body1</div>
            </li>
            <li>
                <div class="header">head2</div>
                <div class="body">body2</div>
            </li>   
        </ul>
    </div>
</div>

CSS--

#head {
    position : absolute;
    top      : 60px;
    left     : 10px;
    right    : 0;
    z-index  : 10;
}
#scroll{
    position: absolute;
    height: 300px;
    width: 200px;
    top: 60px;
    right: 10px;
    bottom: 60px:
    left: 10px;
    background: rgba(245,245,245,1);
}

#content{
    min-height: 100%;
    width: 200px;   
}

.header{
    width: 198px;
    height: 30px;
    background: rgba(234,235,244,1);
    border: 1px solid white;
    text-align: center;
    padding-top: 10px;
}

.body{
    width: 198px;
    height: 300px;
    background: rgba(224,225,234,1);
    border-left: 1px solid white;
    border-right: 1px solid white;
    border-bottom: 1px solid white;
    text-align: center;
    padding-top: 10px;
}

body{
    background: rgba(234,234,234,1);
    font-family: sans-serif;
    color: rgba(34,34,34,0.7);
}

#iphonewrap{
    position: absolute;
    height: 420px;
    width: 220px;
    left: 50%;
    top: 50%;
    margin-left: -110px;
    margin-top: -210px;
    background: black;
    border-radius: 20px;
    border: 1px solid gray;
}

setTimeout 存在,因此滚动可以在滚动结束位置的值之前发生可用。

vender prefix 变量是从 iScroll 应用的第一个样式中提取的。

Boom: http://jsfiddle.net/jasper/tdQmQ/11/ (Updated to include the touchend event as well as mouseup)

JS--

var scroller = new iScroll('scroll',{snap:'.header'}),
    $headers = $('.header:not(.fixed)'),
    prefix   = $('#content')[0].style[0].replace('transition-property', '');

$('#content').on('mouseup touchend', function () {
    setTimeout(function () {
        var y  = $('#content').css(prefix + 'transform').replace(')', '').split(',')[5],
            of = {index : 0, offset : 10000};

        $headers.each(function (index, obj) {
            var tmp = Math.abs($(this).position().top + parseInt(y));
            //console.log($(this).position().top + ' + ' + parseInt(y) + ' = ' + tmp);
            if (tmp < of.offset) {
                of.offset = tmp;
                of.index  = index;
            }
        });
        //console.log(of.index + ' = ' + of.offset);
        $('#head').text($headers.eq(of.index).text());
    }, 500);
});

HTML--

<div id="iphonewrap">
    <div class="header fixed" id="head">head1</div>
    <div id="scroll">
        <ul id="content">
            <li>
                <div class="header">head1</div>
                <div class="body">body1</div>
            </li>
            <li>
                <div class="header">head2</div>
                <div class="body">body2</div>
            </li>   
        </ul>
    </div>
</div>

CSS--

#head {
    position : absolute;
    top      : 60px;
    left     : 10px;
    right    : 0;
    z-index  : 10;
}
#scroll{
    position: absolute;
    height: 300px;
    width: 200px;
    top: 60px;
    right: 10px;
    bottom: 60px:
    left: 10px;
    background: rgba(245,245,245,1);
}

#content{
    min-height: 100%;
    width: 200px;   
}

.header{
    width: 198px;
    height: 30px;
    background: rgba(234,235,244,1);
    border: 1px solid white;
    text-align: center;
    padding-top: 10px;
}

.body{
    width: 198px;
    height: 300px;
    background: rgba(224,225,234,1);
    border-left: 1px solid white;
    border-right: 1px solid white;
    border-bottom: 1px solid white;
    text-align: center;
    padding-top: 10px;
}

body{
    background: rgba(234,234,234,1);
    font-family: sans-serif;
    color: rgba(34,34,34,0.7);
}

#iphonewrap{
    position: absolute;
    height: 420px;
    width: 220px;
    left: 50%;
    top: 50%;
    margin-left: -110px;
    margin-top: -210px;
    background: black;
    border-radius: 20px;
    border: 1px solid gray;
}

The setTimeout is there so the scroll can occur before values for where the scroll ends will be available.

The vender prefix variable is pulled from the first style applied by iScroll.

睫毛上残留的泪 2024-12-26 23:18:26

我终于构建了我想要的东西, http://jsfiddle.net/tdQmQ/25 - 仍然需要修复 z-index,以便标题显示在克隆框上方。

I finally built what I was looking for, http://jsfiddle.net/tdQmQ/25 - still need to fix the z-index so headers show above the clone box though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文