简单的下拉刷新

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        body{
            margin:0;
            padding:0;
            font-size: 3rem;
        }

    </style>
</head>
<body>
    <div style='height:0;width:500px;text-align:center;position: relative;' class='xl'><span style='position: absolute;bottom: 10px;'>↓下拉更新</span></div>
    <div class='app' style='width:500px;height:500px;background: lightblue'></div>
</body>
<script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
    var S={
        xiala:function(e,fn){
            var dist=0;window.val=0;
            e.on('touchstart',function(e){
                dist=e.touches[0].pageY;
            })
            e.on('touchmove',function(e){
                val=Math.abs(e.touches[0].pageY-dist);
                // console.log(val);
                if(val>250){
                    $('.xl span').text('↑释放更新')
                }
                $('.xl').css('height',val);
            })
            e.on('touchend',function(e){
                $('.xl').css('transition','height 500ms')
                $('.xl').css('height','200px');

            })
            $('.xl').on('webkitTransitionEnd',function(){
                $('.xl').css('transition','height 0ms ')
                $('.xl span').text('↓下拉更新')
                fn&&fn();
                $('.xl').animate({height:'0'})
            })
        }
    }
    S.xiala($('.app'),function(){alert(2)})
</script>
</html>

下拉的显示的div,最好是写进方法里,prepend()插入头部,这里就不写了。

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容