123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- $(function(){
-
- var index = 0;
-
- function LScroll(opts){
- var options = {
- id: "",
- style: "",
-
- pullUpElId: ".l-pullUp",
- pullUpAction: undefined,
-
- pullDownElId: ".l-pullDown",
- pullDownAction: undefined,
- pullDownMsg1: "下拉刷新...",
- pullDownMsg2: "松手开始更新...",
- type: 1, // 1:正常 上拉加载 下拉刷新 2:下拉加载
- page: 1,
- scrollCallBack: undefined,
- scrollEndCallBack: undefined,
- top: 0,
- // IScroll 配置
- iscrollOpt: null
- }
- var g= this;
- g.options = $.extend(true, options, opts);
- g.iScroll = undefined;
- g.noMore = false;
- }
-
- LScroll.prototype.refresh = function(noMore){
- var g= this,
- p = g.options;
- if(typeof(noMore) == 'boolean'){
- g.noMore = noMore;
- }
- g.iScroll.refresh();
- }
-
- LScroll.prototype.scrollToElement = function(el, time, offsetX, offsetY, easing){
- var g= this,
- is = g.iScroll;
- is.scrollToElement(el, time, offsetX, offsetY, easing);
- }
-
- LScroll.prototype.refreshToEnd = function(time){
- var g= this,
- p = g.options,
- is = g.iScroll;
- is.refresh();
- time = time || 0;
- is.scrollTo(0, is.maxScrollY, time);
- }
-
- LScroll.prototype.refreshToTop = function(time){
- var g= this,
- p = g.options,
- is = g.iScroll;
- is.refresh();
- time = time || 0;
- is.scrollTo(0, 0, time);
- }
-
- LScroll.prototype.scrollToEnd = function(time){
- var g= this,
- p = g.options,
- is = g.iScroll;
- time = time || 0;
- var wrapperHeight = $(myScroll.iScroll.wrapper).height();
- is.scrollTo(0, wrapperHeight-is.scrollerHeight, time);
- }
-
- LScroll.prototype.init = function(){
-
- var g= this,
- p = g.options;
- p.id = p.id || ("wrapper"+ index);
- p.style = p.style || "";
- if(p.top){
- p.style = "top:"+ p.top + "px;"+p.style;
- }
- p._el.wrap('<div id="'+ p.id +'" class="l-wrapper" style="'+ p.style +'"><div class="l-scroller"></div></div>')
-
- var _el = $('#'+p.id);
- if(p.pullDownAction){
- $('#'+p.id+ ' div.l-scroller').prepend('<div class="l-pullDown"><label class="pullDownLabel">'+ p.pullDownMsg1+'</label></div>');
- }
-
- if(p.pullUpAction){
- $('#'+p.id+ ' div.l-scroller').append('<div class="l-pullUp l-loading"><label class="pullUpLabel">上拉加载更多...</label></div>');
- }
-
- var pullUpEl= _el[0].querySelector(p.pullUpElId),
- pullUpOffset,
-
- pullDownEl= _el[0].querySelector(p.pullDownElId),
- pullDownOffset;
-
-
- g.iScroll = new IScroll(_el[0], $.extend({
- probeType: 3
- },g.options.iscrollOpt));
- var myScroll = g.iScroll;
- myScroll.on('refresh', function(){
- $(pullUpEl).show();
- $(pullDownEl).show();
- if (pullUpEl) {
- if(g.noMore){
- pullUpEl.className = 'noMoreData';
- pullUpEl.querySelector('.pullUpLabel').innerHTML = '没有更多数据...';
- } else{
- pullUpEl.className = 'l-pullUp';
- pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
- }
- } else if(pullDownEl) {
- if(g.noMore){
- if(p.type == 2){
- pullDownEl.className = 'noMoreData';
- pullDownEl.querySelector('.pullDownLabel').innerHTML = "没有更多数据...";
- } else if(pullUpEl) {
- pullUpEl.className = 'noMoreData';
- pullUpEl.querySelector('.pullUpLabel').innerHTML = '没有更多数据...';
- }
- } else{
- pullDownEl.className = 'l-pullDown';
- pullDownEl.querySelector('.pullDownLabel').innerHTML = p.pullDownMsg1;
- if(pullUpEl){
- pullUpEl.className = 'l-pullUp';
- pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
- }
- }
- }
- });
-
- myScroll.on('scroll', function(){
-
- if (pullDownEl && this.y > 30 && !pullDownEl.className.match('l-flip')) {
- if(pullDownEl.className.match('noMoreData'))
- return;
-
- pullDownEl.className = 'l-flip';
- pullDownEl.querySelector('.pullDownLabel').innerHTML = p.pullDownMsg2 ;
- this.minScrollY = pullDownEl.offsetHeight;
- } else if (pullDownEl && this.y < 30 && pullDownEl.className.match('l-flip')) {
- if(pullDownEl.className.match('noMoreData'))
- return;
-
- pullDownEl.className = 'l-pullDown';
- pullDownEl.querySelector('.pullDownLabel').innerHTML = p.pullDownMsg1;
- // this.minScrollY = pullDownOffset;
- } else if (pullUpEl && this.y < (this.maxScrollY - 30) && !pullUpEl.className.match('l-flip')) {
- if(pullUpEl.className.match('noMoreData'))
- return;
- pullUpEl.className = 'l-flip';
- pullUpEl.querySelector('.pullUpLabel').innerHTML = '松手开始加载...';
- this.maxScrollY = this.maxScrollY;
- } else if (pullUpEl && this.y > (this.maxScrollY + 30) && pullUpEl.className.match('l-flip')) {
- if(pullUpEl.className.match('noMoreData'))
- return;
- pullUpEl.className = 'l-pullDown';
- pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
- this.maxScrollY = pullUpEl.offsetHeight;
- }
-
- if(p.scrollCallBack)
- p.scrollCallBack(this);
- });
-
- myScroll.on('scrollEnd', function(){
-
- if (pullDownEl && pullDownEl.className.match('l-flip')) {
- if(pullDownEl.className.match('noMoreData'))
- return;
-
- pullDownEl.className = 'l-loading';
- pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中...';
- if(p.type == 2)
- ++p.page;
- else
- p.page = 1;
- p.noMore = false;
- pullDownEl.className= "l-loading";
- if(p.pullDownAction) p.pullDownAction(g);
- } else if (pullUpEl && pullUpEl.className.match('l-flip')) {
- if(pullUpEl.className.match('noMoreData'))
- return;
-
- pullUpEl.className = 'l-loading';
- pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';
- ++p.page;
- if(p.pullUpAction) p.pullUpAction(g);
- }
- if(p.scrollEndCallBack)
- p.scrollEndCallBack(this);
- });
-
- // setTimeout(function () { p._el[0].style.left = '0'; }, 800);
- return myScroll;
- }
-
- $.fn.lscroll = function (opts) {
- index++;
- opts = opts || {};
- opts._el = $(this);
- var o = new LScroll(opts);
- var myScroll = o.init();
-
- this.data("LScroll", myScroll);
- return o;
- };
-
- $.fn.getLScroll = function () {
- return this.data("LScroll");
- };
-
- document.addEventListener('touchmove', function (e) {
- //判别输入框的id
- var that = e;
- if(that.target.parentNode.parentNode.id && that.target.id != "input_content"){
- if(that.target.parentNode.parentNode.id != "history_search"){
- that.preventDefault();
- }
- }else{
- if(that.target.id != "input_content"){
- that.preventDefault();
- }
- }
- }, false);
- })
-
|