ng-iScroll icon indicating copy to clipboard operation
ng-iScroll copied to clipboard

Pull down to refresh example?

Open cliffsun91 opened this issue 11 years ago • 9 comments

Hi, does this module support pull down to refresh? If so is there a quick example of how to do it? I've tried to follow the example from the iscroll website (http://cubiq.org/dropbox/iscroll4/examples/pull-to-refresh/) but the iscroll options involve accessing the DOM and manipulating it. I was wondering if there was a proper way to do it.

Thanks!

cliffsun91 avatar Oct 28 '13 10:10 cliffsun91

I'm waiting too!

diegolameira avatar Dec 02 '13 18:12 diegolameira

hi, I write an AngularJS directive for use pull to refresh with this module: https://github.com/mboulord/ng-iScroll-pull-to-refresh

mboulord avatar Dec 09 '13 18:12 mboulord

All right, but how about ng-scroll#v1.2b and iScroll 5?

diegolameira avatar Dec 26 '13 13:12 diegolameira

this is my code for both pull-to-refresh and infinite-scroll using my own version of ng-iscroll (https://github.com/ibspoof/ng-iScroll/pull/12) and iscroll 5

$scope.loading = search.loading;
$scope.yStartFromZero = false;

$scope.$parent.myScrollOptions = {
    'list_wrapper': {
        snap: false,
        scrollbars: 'custom',
        fadeScrollbars: true,
        probeType: 2,
        //mouseWheel: true,
        interactiveScrollbars: true,
        //preventDefault: false,
        on: [
            { beforeScrollStart: function () {
                if (this.y === 0) {
                    $scope.yStartFromZero = true;
                }

            }},
            { scrollEnd: function () {
                if ($scope.yStartFromZero && this.directionY === -1) {
                    this._execEvent("pullToRefresh");
                }
                $scope.yStartFromZero = false;
                $scope.infiniteScroll = false;
            }},
            { pullToRefresh: function () {
                console.log('Pull to Refresh!');
            }},
            { scroll: function () {
                if (!$scope.infiniteScroll && !search.loading && !search.endlist && (this.y <= this.maxScrollY + 800)) {
                    $scope.infiniteScroll = true;
                    search.__search();
                }
            }}
        ]
    }
}; 

JonnyBGod avatar Jan 13 '14 16:01 JonnyBGod

JonnyBGod, thanks for the JS snippet. Could you provide the HTML as well on how do you use it as whole example? I am having trouble with this code as I tried to implement it in my case but have struggled with it.

BR

vaskgjuri avatar Jan 28 '14 23:01 vaskgjuri

Sure, my html is as simple as:

<div ng-iscroll='list_wrapper'>
  <div>
    <div class="YOUR CONTENT" ng-repeat="i in items track by i.id">
    </div>
  <div>
</div>

JonnyBGod avatar Jan 29 '14 00:01 JonnyBGod

I thought my problem was with the html implementation but it seems like we are ok on that side. The problem I am having is that the pull down to refresh does not load on initial page load, but rather when I refresh the view. Any thoughts on why could this be happening?

BR

vaskgjuri avatar Jan 29 '14 09:01 vaskgjuri

I've prepared a demo - hope this helps: http://pnc.co.il/dev/iscroll-5-pull-to-refresh-and-infinite-demo.html

The DEMO includes both Pull to Refresh and "infinite" scroll (but not using the iscroll-infinite.js).

orenagiv avatar Jul 12 '14 20:07 orenagiv

Hi, I am using iscroll5 and TopOffset is not working and i am pasting my code and pull to refresh is not working can any one help me and make necessary change to work pull to refresh and it is an urgent requirement for production fix.

function createScroller(wrapper, pullDownAction, scrollStart, scrollMove, scrollEnd, beforeScrollStart, enableBeforeScrollStart) { var myScroll, pullDownEl, pullDownOffset = 0;

        var wrapperEl = typeof wrapper == 'object' ? wrapper : doc.getElementById(wrapper);
        var scrollerEl = wrapperEl.children[0];
        $(scrollerEl).prepend("<div class='pullDown'></div>");
        pullDownEl = $(scrollerEl).find('.pullDown')[0];
        pullDownOffset = pullDownEl.offsetHeight;
        myScroll = new IScrollV5(wrapper, {
            mouseWheel: true,
            hideScrollbar: true,
            fadeScrollbar: true,
            useTransition: true,
            click: true,
            scrollbarClass: 'Scrollbar',
            topOffset: pullDownOffset,
        });
        myScroll.on("scrollMove", function () {
            if (this.y > 5 && !pullDownEl.className.match('flip')) {
                pullDownEl.className = 'flip';
                this.minScrollY = 0;
            } else if (this.y < 5 && pullDownEl.className.match('flip')) {
                pullDownEl.className = '';
                this.minScrollY = -pullDownOffset;
            }
            if (scrollMove != undefined)
                scrollMove();
        });
        myScroll.on("scrollEnd", function () {
            if (pullDownEl.className.match('flip')) {
                pullDownEl.className = 'pullDownloading';
                pullDownAction(this);
            }
            if (scrollEnd != undefined)
                scrollEnd();
        });
        myScroll.on("refresh", function () {
            if (pullDownEl.className.match('pullDownloading')) {
                pullDownEl.className = '';
            }
        });
    }

    return myScroll;

} var scroller = { createScroller: createScroller, }

return scroller;

});

pmadhu420 avatar Aug 27 '16 05:08 pmadhu420