html5+css3实现手机下拉和下拉刷新

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>html5+css3实现上拉和下拉刷新</title>

<script type="text/javascript" src="http://statics.webkfa.com/js/iscroll.js"></script>

<script type="text/javascript">

var myScroll,
    pullDownEl, pullDownOffset,
    pullUpEl, pullUpOffset,
    generatedCount = 0;

function pullDownAction () {
    setTimeout(function () {    // <-- Simulate network congestion, remove setTimeout from production!
        var el, li, i;
        el = document.getElementById(‘thelist‘);

        for (i=0; i<3; i++) {
            li = document.createElement(‘li‘);
            li.innerText = ‘Generated row ‘ + (++generatedCount);
            el.insertBefore(li, el.childNodes[0]);
        }

        myScroll.refresh();        // Remember to refresh when contents are loaded (ie: on ajax completion)
    }, 1000);    // <-- Simulate network congestion, remove setTimeout from production!
}

function pullUpAction () {
    setTimeout(function () {    // <-- Simulate network congestion, remove setTimeout from production!
        var el, li, i;
        el = document.getElementById(‘thelist‘);

        for (i=0; i<3; i++) {
            li = document.createElement(‘li‘);
            li.innerText = ‘Generated row ‘ + (++generatedCount);
            el.appendChild(li, el.childNodes[0]);
        }

        myScroll.refresh();        // Remember to refresh when contents are loaded (ie: on ajax completion)
    }, 1000);    // <-- Simulate network congestion, remove setTimeout from production!
}

function loaded() {
    pullDownEl = document.getElementById(‘pullDown‘);
    pullDownOffset = pullDownEl.offsetHeight;
    pullUpEl = document.getElementById(‘pullUp‘);
    pullUpOffset = pullUpEl.offsetHeight;

    myScroll = new iScroll(‘wrapper‘, {
        useTransition: true,
        topOffset: pullDownOffset,
        onRefresh: function () {
            if (pullDownEl.className.match(‘loading‘)) {
                pullDownEl.className = ‘‘;
                pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘Pull down to refresh...‘;
            } else if (pullUpEl.className.match(‘loading‘)) {
                pullUpEl.className = ‘‘;
                pullUpEl.querySelector(‘.pullUpLabel‘).innerHTML = ‘Pull up to load more...‘;
            }
        },
        onScrollMove: function () {
            if (this.y > 5 && !pullDownEl.className.match(‘flip‘)) {
                pullDownEl.className = ‘flip‘;
                pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘Release to refresh...‘;
                this.minScrollY = 0;
            } else if (this.y < 5 && pullDownEl.className.match(‘flip‘)) {
                pullDownEl.className = ‘‘;
                pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘Pull down to refresh...‘;
                this.minScrollY = -pullDownOffset;
            } else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match(‘flip‘)) {
                pullUpEl.className = ‘flip‘;
                pullUpEl.querySelector(‘.pullUpLabel‘).innerHTML = ‘Release to refresh...‘;
                this.maxScrollY = this.maxScrollY;
            } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match(‘flip‘)) {
                pullUpEl.className = ‘‘;
                pullUpEl.querySelector(‘.pullUpLabel‘).innerHTML = ‘Pull up to load more...‘;
                this.maxScrollY = pullUpOffset;
            }
        },
        onScrollEnd: function () {
            if (pullDownEl.className.match(‘flip‘)) {
                pullDownEl.className = ‘loading‘;
                pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘Loading...‘;
                pullDownAction();    // Execute custom function (ajax call?)
            } else if (pullUpEl.className.match(‘flip‘)) {
                pullUpEl.className = ‘loading‘;
                pullUpEl.querySelector(‘.pullUpLabel‘).innerHTML = ‘Loading...‘;
                pullUpAction();    // Execute custom function (ajax call?)
            }
        }
    });

    setTimeout(function () { document.getElementById(‘wrapper‘).style.left = ‘0‘; }, 800);
}

document.addEventListener(‘touchmove‘, function (e) { e.preventDefault(); }, false);

document.addEventListener(‘DOMContentLoaded‘, function () { setTimeout(loaded, 200); }, false);
</script>

<style type="text/css" media="all">
body,ul,li {
    padding:0;
    margin:0;
    border:0;
}

body {
    font-size:12px;
    -webkit-user-select:none;
    -webkit-text-size-adjust:none;
    font-family:helvetica;
}

#header {
    position:absolute; z-index:2;
    top:0; left:0;
    width:100%;
    height:45px;
    line-height:45px;
    background-color:#d51875;
    background-image:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #fe96c9), color-stop(0.05, #d51875), color-stop(1, #7b0a2e));
    background-image:-moz-linear-gradient(top, #fe96c9, #d51875 5%, #7b0a2e);
    background-image:-o-linear-gradient(top, #fe96c9, #d51875 5%, #7b0a2e);
    padding:0;
    color:#eee;
    font-size:20px;
    text-align:center;
}

#header a {
    color:#f3f3f3;
    text-decoration:none;
    font-weight:bold;
    text-shadow:0 -1px 0 rgba(0,0,0,0.5);
}

#footer {
    position:absolute; z-index:2;
    bottom:0; left:0;
    width:100%;
    height:48px;
    background-color:#222;
    background-image:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #999), color-stop(0.02, #666), color-stop(1, #222));
    background-image:-moz-linear-gradient(top, #999, #666 2%, #222);
    background-image:-o-linear-gradient(top, #999, #666 2%, #222);
    padding:0;
    border-top:1px solid #444;
}

#wrapper {
    position:absolute; z-index:1;
    top:45px; bottom:48px; left:-9999px;
    width:100%;
    background:#aaa;
    overflow:auto;
}

#scroller {
    position:absolute; z-index:1;
/*    -webkit-touch-callout:none;*/
    -webkit-tap-highlight-color:rgba(0,0,0,0);
    width:100%;
    padding:0;
}

#scroller ul {
    list-style:none;
    padding:0;
    margin:0;
    width:100%;
    text-align:left;
}

#scroller li {
    padding:0 10px;
    height:40px;
    line-height:40px;
    border-bottom:1px solid #ccc;
    border-top:1px solid #fff;
    background-color:#fafafa;
    font-size:14px;
}

#myFrame {
    position:absolute;
    top:0; left:0;
}

/**
 *
 * Pull down styles
 *
 */
#pullDown, #pullUp {
    background:#fff;
    height:40px;
    line-height:40px;
    padding:5px 10px;
    border-bottom:1px solid #ccc;
    font-weight:bold;
    font-size:14px;
    color:#888;
}
#pullDown .pullDownIcon, #pullUp .pullUpIcon  {
    display:block; float:left;
    width:40px; height:40px;
    background:url(http://statics.webkfa.com/img/[email protected]) 0 0 no-repeat;
    -webkit-background-size:40px 80px; background-size:40px 80px;
    -webkit-transition-property:-webkit-transform;
    -webkit-transition-duration:250ms;
}
#pullDown .pullDownIcon {
    -webkit-transform:rotate(0deg) translateZ(0);
}
#pullUp .pullUpIcon  {
    -webkit-transform:rotate(-180deg) translateZ(0);
}

#pullDown.flip .pullDownIcon {
    -webkit-transform:rotate(-180deg) translateZ(0);
}

#pullUp.flip .pullUpIcon {
    -webkit-transform:rotate(0deg) translateZ(0);
}

#pullDown.loading .pullDownIcon, #pullUp.loading .pullUpIcon {
    background-position:0 100%;
    -webkit-transform:rotate(0deg) translateZ(0);
    -webkit-transition-duration:0ms;

    -webkit-animation-name:loading;
    -webkit-animation-duration:2s;
    -webkit-animation-iteration-count:infinite;
    -webkit-animation-timing-function:linear;
}

@-webkit-keyframes loading {
    from { -webkit-transform:rotate(0deg) translateZ(0); }
    to { -webkit-transform:rotate(360deg) translateZ(0); }
}

</style>
</head>
<body>

<div id="header"><a href="http://cubiq.org/iscroll">iScroll</a></div>
<div id="wrapper">
    <div id="scroller">
        <div id="pullDown">
            <span class="pullDownIcon"></span><span class="pullDownLabel">Pull down to refresh...</span>
        </div>

        <ul id="thelist">
            <li>Pretty row 1</li>
            <li>Pretty row 2</li>
            <li>Pretty row 3</li>
            <li>Pretty row 4</li>
            <li>Pretty row 5</li>
            <li>Pretty row 6</li>
            <li>Pretty row 7</li>
            <li>Pretty row 8</li>
            <li>Pretty row 9</li>
            <li>Pretty row 10</li>
            <li>Pretty row 11</li>
            <li>Pretty row 12</li>
            <li>Pretty row 13</li>
            <li>Pretty row 14</li>
            <li>Pretty row 15</li>
            <li>Pretty row 16</li>
            <li>Pretty row 17</li>
            <li>Pretty row 18</li>
            <li>Pretty row 19</li>
            <li>Pretty row 20</li>
            <li>Pretty row 21</li>
            <li>Pretty row 22</li>
            <li>Pretty row 23</li>
            <li>Pretty row 24</li>
            <li>Pretty row 25</li>
            <li>Pretty row 26</li>
            <li>Pretty row 27</li>
            <li>Pretty row 28</li>
            <li>Pretty row 29</li>
            <li>Pretty row 30</li>
            <li>Pretty row 31</li>
            <li>Pretty row 32</li>
            <li>Pretty row 33</li>
            <li>Pretty row 34</li>
            <li>Pretty row 35</li>
            <li>Pretty row 36</li>
            <li>Pretty row 37</li>
            <li>Pretty row 38</li>
            <li>Pretty row 39</li>
            <li>Pretty row 40</li>
        </ul>
        <div id="pullUp">
            <span class="pullUpIcon"></span><span class="pullUpLabel">Pull up to refresh...</span>
        </div>
    </div>
</div>
<div id="footer"></div>

</body>
</html>
时间: 2024-10-24 18:06:03

html5+css3实现手机下拉和下拉刷新的相关文章

HTML5移动端手机网站开发流程

最近一直在研究移动手机网站的开发,发现做手机网站没有想象中的那么难.为什么会这么说呢?我们试想下:我们连传统的PC网站都会做,难道连一个小小的手机网站难道都搞不定吗?其实手机网站就是一个微缩版的PC网站罢了!至于为什么觉得难.觉得无从下手. 段亮觉得有以下几点: 一.没有完整的思路和流程 就像做网站的流程一样,如果你能知道它的流程,我相信就不会觉得做手机网站难!真正难的是你没有思路. 二.把html5这门技术想的高深莫测 好像觉得学会用html5+css3做手机网站,就相当于学会了顶尖的绝世武功

精心挑选的HTML5/CSS3应用及源码

这段时间我已经为大家分享了不少关于HTML5应用和jQuery插件了,先来回顾一下: 炫酷霸气的HTML5/jQuery应用及源码 干货分享 超炫丽的HTML5/jQuery应用及代码 绚丽而实用的jQuery/CSS3应用及源码 今天我们继续来介绍一些新鲜的HTML5/CSS3应用及源码,希望大家会喜欢.HTML5是WEB的未来,我们需要不断学习. HTML5 3D骨牌图片特效 很不错的HTML5 3D图片动画特效,图片也不再是平面的了. 核心CSS代码: figure { margin: 0

html5+css3实现上拉和下拉刷新

<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-sc

html5 + css3 带音效下拉菜单的实现

原文:scripts tutorials    (来自脚本教程网的教程,翻译可能有些不对...想要试试 音效下拉菜单 在这个教程中我们将讲述如何开发酷炫的音效下拉菜单(html5 + css3).下拉菜单有css3动画效果(菜单元素有整洁的悬浮特效)同时也使用了html5的Audio元素来添加菜单的音效,准备好了吗?那就开始吧. Musical drop down menu Our new tutorial tells about developing cool musical drop dow

11个优秀的HTML5 &amp; CSS3下拉菜单制作教程

下拉菜单是一个很常见的效果,在网站设计中被广泛使用.通过使用下拉菜单,设计者不仅可以在网站设计中营造出色的视觉吸引力,但也可以为网站提供了一个有效的导航方案.使用HTML5和CSS3可以更容易创造视觉上充满吸引力的下拉菜单. 1.Stunning Menu in CSS3 效果很精美CSS3菜单,可以让给你的网站提升一个层次.制作教程非常详细. 在线演示 源码下载 2.Click action Multi-level CSS3 Dropdown Menu 这是一个点击弹出的下拉菜单,传统的下拉菜

巧用CSS3 :target 伪类制作Dropdown下拉菜单(无JS)

:target 是CSS3 中新增的一个伪类,用以匹配当前页面的URI中某个标志符的目标元素(比如说当前页面URL下添加#comment就会定位到id=“comment”的位置,俗称锚).CSS3 为这个动作赋予了更加多的功能——就如同:hover 一样你可以做一些样式定义. 先上效果图 正如标题所说,本文是教你如何巧用CSS3 :target 伪类制作Dropdown下拉菜单,原生HTML+CSS,无JavaScript.为了吸引各位往下看,先上实际例子,再进行剖析. Duang~ 实际例子其

CSS3实现的一款三级下拉菜单

<html> <head> <title>河北礼品公司</title> <style> body { background:#eee; margin:0; padding:0; } .example { background:#fff url(/imagesforcode/201306/clouds-in-blue-sky.jpg); width:770px; height:570px; border:1px #000 solid; margin

手机影音第十三天,xutils3、Glide的使用获取网络图片;下拉、上滑刷新;缓存网络资源

代码已经托管到码云上,感兴趣的小伙伴可以下载看看 https://git.oschina.net/joy_yuan/MobilePlayer 本次的网络资源地址使用的是时光网的api接口,地址如下: http://api.m.mtime.cn/PageSubArea/TrailerList.api 效果如下: 一.Xutils3 的使用 去github上看详解:https://github.com/wyouflf/xUtils3 xUtils3简介 xUtils 包含了orm, http(s),

Html5+css3+angularjs+jquery+webAPi 开发手机web(一)

前言 随着浏览器的发展 HTML5+CSS3 的使用也越来越广泛,一直想学这个,想学那个折腾下来几乎没学到什么东西.工作经验告诉我,要掌握一门技术,就需要在项目中去磨练, 所以我就准备开发一个手机端的BBS练练手,技术更新快,也要学的快,跟的上时代,才涨的了工资. 技术的选择 jQuery Mobile  Phone Gap  等都是比较成熟的框架为什么我不用这些框架呢? 因为我考虑到底层的技术应用和练习 . 我的选择是:Html5+css3+angularjs+jquery HTML5+CSS