angular之上滑换页指令

healthmallDirectives.directive("goodsTopRefresh", ['$window',function ($window) {
        return {
            link: function (scope,el,attrs) {
                var wai = $window.document.getElementById("outerDiv");
                var content = $window.document.getElementById("goodsnei")

                wai.addEventListener("scroll", function (e) {
                    var waiHeight = wai.offsetHeight;
                    var contentHeight = content.offsetHeight;
                    var waiTop = wai.scrollTop;
                    if(waiTop+ waiHeight-40 >= contentHeight){
                        var startY;
                        var endY;
                        content.addEventListener("touchstart", function (e){
                            startY = e.changedTouches[0].pageY;
                        });
                        content.addEventListener("touchend", function (e){
                            endY= e.changedTouches[0].pageY;
                            if(startY -endY>=80){
                                scope.$apply(attrs.toptorefresh);
                            }
                        });

                    }
                })
            }

        };
    }]);

  获得滚动页的大小和内容页大小,通过touchStart和touchEnd判断页面是否是上滑,若上滑则执行toptorefresh属性中的方法

posted @ 2016-11-30 11:32  bxl2016  阅读(635)  评论(0编辑  收藏  举报