/** * 星潮教室-星搭配分页加载 * @author: wsl<shuiling.wang@yoho.cn> * @date: 2016/4/12 */ var $ = require('yoho-jquery'), tip = require('../plugin/tip'), loading = require('../plugin/loading'), lazyLoad = require('yoho-jquery-lazyload'), ellipsis = require('yoho-mlellipsis'); var stopLoading = false, page = 1; require('./list-common'); ellipsis.init(); function massageAJAX(pageData) { var $this, $title, $cont; loading.showLoadingMask(); $.ajax({ type: 'GET', url: '/guang/star/collocation/list', data: { page: pageData, appVersion: window.queryString.app_version }, dataType: 'html', success: function(data) { stopLoading = false; if (data === '') { stopLoading = true; tip.show('没有更多内容了'); } $('.collocation-list').append(data); // 限制标题字数 $('.cont-area').each(function() { $this = $(this); $title = $this.find('.title'); $cont = $this.find('.cont-txt'); $title[0].mlellipsis(2); $cont[0].mlellipsis(2); }); loading.hideLoadingMask(); lazyLoad($('img.lazy')); }, error: function() { tip.show('网络断开连接了~'); } }); } function scrollHandler() { if (!stopLoading && ($(window).scrollTop() + $(window).height() > $('body').height() * 0.75)) { stopLoading = true; page++; massageAJAX(page); } } $(window).scroll(function() { window.requestAnimationFrame(scrollHandler); }); if ($('.collocation-list').find('li').length === 0) { massageAJAX(1); }