Iscroll5-上下拉动刷新

本文介绍了一个Angular模块的实现,用于在页面滚动到特定百分比时触发JS表达式,包括设置滚动监听和使用IScroll库进行页面滚动管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自: http://www.cnblogs.com/mrxia/p/3868126.html

具体的文章我就不转载了. 粘贴下公司项目逇实现吧


<span style="font-size:14px;">/*@author Tushar Borole
 * @description user has to jsut mention the percent, on completion of that percentage scroll; expression will be fired
 * for example <div id="fixed" when-scrolled="loadMore()" percent="70">*/

var scroll = angular.module('angular-scroll-complete', []);

scroll.run(function() {
	document.ontouchmove = function(e) {
		e.preventDefault();
	};
});

scroll.directive('whenScrolled', function () {
    return function ($scope, elm, attr) {
        var raw = elm[0];
        var scrollCompleted = true;
		
        $scope.$on('scrollCompleted', function () {
            scrollCompleted = true;
        });

		$scope.scrollCompleted = function() {
			scrollCompleted = true;
		};

        elm.bind('scroll', function() {
			var scroll = elm.data("iscroll");

            var remainingHeight = raw.offsetHeight - raw.scrollHeight;
            var scrollTop = raw.scrollTop;	

			if (scroll != null)
				scrollTop = scroll.y;

            var percent = Math.abs((scrollTop / remainingHeight) * 100);
			
            if (percent > attr.percent) {
                if (scrollCompleted) {
                    scrollCompleted = false;
                    $scope.$apply(attr.whenScrolled);
                }
            }
        });
    };
});

scroll.directive('ngScroll', function($interval) {
	return function($scope, elm, attr) {
		if (elm.children().length > 1)
		{
			elm.children().wrapAll("<div></div>");
		}

		var scroll = new IScroll(elm[0], {
			bounce: false,
			scrollbars: false,
			click: true,
			probeType: 1
		});

		elm.data("iscroll", scroll);

		scroll.on("scroll", function() {
			elm.scroll();
		});

		$interval(function() {
			try
			{
				scroll.refresh();
			} catch(err)
			{ }
		}, 500);
	};
});
</span>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值