当前位置: 首页 > news >正文

企业网站做百度小程序/排名函数

企业网站做百度小程序,排名函数,dede 网站内页标题修改,b2c跨境电商网站有哪些// PageSlide接收三个参数:页面元素,要设定的滑动方向,可选的扩展函数 var PageSlide function(el, swipe, options) { this.options options || {}; //可选函数 this.current 0; //当前页面索引 this.pageX; //横向的手指落点 this.pageY; //纵向的手指落点 this.height…

// PageSlide接收三个参数:页面元素,要设定的滑动方向,可选的扩展函数

var PageSlide = function(el, swipe, options) {

    this.options = options || {}; //可选函数

    this.current = 0;  //当前页面索引

    this.pageX;  //横向的手指落点

    this.pageY;  //纵向的手指落点

    this.height; //设备高度

    this.width;  //设备宽度

    this.flag;  //判断滑动方向的变量

    this.move;  //滑动的距离

    this.$el = el; //当前页面的对象

    this.swipe = swipe || 'X'; //滑动方向参数

    this.resize().init().bindEvents(); //初始化

}

PageSlide.prototype.init = function(i) {

    var current = i ? this.$el.children[i] : this.$el.firstElementChild;

    if (!current) throw 'ERROR';

//moving类名作为当前滑动页面的标记,也在样式中作滑动的扩展效果

    current.classList.add('moving');

    current.style.webkitTransform = 'translate3d(0,0,0)';

//以swipe的值预设置其他页面的宽高,获得流畅的交互效果

for(var i = 1; i <this.$el.children.length ; i++){

        this['set' + this.swipe](this.$el.children[i],  (this.swipe === 'X' ? this.width : this.height))

        };

    setTimeout(function() {

        current.classList.remove('moving')

        current.classList.add('play')

    }, 3e2);

    return this

};

//为页面绑定各种事件的绑定函数

PageSlide.prototype.bindEvents = function() {

    var self = this;

    window.addEventListener('resize orientationchange', this.resize.bind(this), false);

    'touchstart touchmove touchend touchcancel'.split(' ').forEach(function(evn) {

   //将四个触控函数(申明在后面)绑定到每个页面

        self.$el.addEventListener(evn, self[evn].bind(self), false);

    });

}

//获得当前触控的页面对象

PageSlide.prototype.getCurrent = function() {

    return this.$el.children[this.current];

};

//初始化时获得设备的宽高

PageSlide.prototype.resize = function() {

    this.width = this.$el.parentNode.clientWidth;

    this.height = this.$el.parentNode.clientHeight;

    return this;

};

//到达任意页面的random()方法

PageSlide.prototype.random = function() {

    var count = this.$el.children.length;

    var current = this.current;

    var arr = [];

    var num;

    for (var i = 0; i < count; i++) {

        if (i !== current) arr.push(i.toString())

    };

    num = Math.floor(Math.random() * arr.length);

    this.direct(+arr[num]);

}

// 四个内建的滑动事件函数,与前面绑定函数相呼应

PageSlide.prototype.touchstart = function(e) {

    var touches = e.touches[0];

    //触控开始

    this.flag = null;

    this.move = 0;

    //记录落点

    this.pageX = touches.pageX;

    this.pageY = touches.pageY;

};

PageSlide.prototype.touchmove = function(e) {

    var touches = e.touches[0];;

    var X = touches.pageX - this.pageX;

    var Y = touches.pageY - this.pageY;

    var current = this.getCurrent();

    var next = current.nextElementSibling;

    var prev = current.previousElementSibling;

    //添加移动样式

    if (!this.flag) {

        this.flag = Math.abs(X) > Math.abs(Y) ? 'X' : 'Y';

        if (this.flag === this.swipe) {

            current.classList.add('moving');

            next && next.classList.add('moving');

            prev && prev.classList.add('moving');

        };

    };

    if (this.flag === this.swipe) {

        e.preventDefault();

        e.stopPropagation();

        switch (this.swipe) {

            case 'X':

                //swipe horizontal

                this.move = X;

                this.setX(current, X);

                next && (this.setX(next, X + this.width));

                prev && (this.setX(prev, X - this.width));

                break;

            case 'Y':

                //swipe vertical

                this.move = Y;

                this.setY(current, Y);

                next && (this.setY(next, Y + this.height));

                prev && (this.setY(prev, Y - this.height));

                break;

        }

    }

}

PageSlide.prototype.touchend = function(e) {

    var minRange = 50;

    var move = this.move;

    var current = this.getCurrent();

    var next = current.nextElementSibling;

    var prev = current.previousElementSibling;

    current.classList.remove('moving');

    next && next.classList.remove('moving');

    prev && prev.classList.remove('moving');

    if (!this.flag) return;

    e.preventDefault();

   //滑动结束前往下一页面,next()方法调用了go()方法

    if (move < -minRange && next) return this.next();

    if (move > minRange && prev) return this.prev();

    this.reset();

}

PageSlide.prototype.touchcancel = function(e) {

    var current = this.getCurrent();

    var next = current.nextElementSibling;

    var prev = current.previousElementSibling;

    current.classList.remove('moving');

    next && next.classList.remove('moving');

    prev && prev.classList.remove('moving');

    this.reset();

}

//动态设定translate3d参数方法

PageSlide.prototype.setX = function(el, x, unit) {

    el && (el.style.webkitTransform = 'translate3d(' + x + (unit || 'px') + ',0,0)');

};

PageSlide.prototype.setY = function(el, y, unit) {

    el && (el.style.webkitTransform = 'translate3d(0,' + y + (unit || 'px') + ',0)');

};

//设置当前触控页面translate3d参数为0的方法

PageSlide.prototype.setCurrent = function(el, i) {

    el && (el.style.webkitTransform = 'translate3d(0,0,0)');

   

    if (i) {

        this.current = i;

        this.$current = this.$el.children[i];

    }

}

//调用go()方法前往下一或上一页面

PageSlide.prototype.next = function() {

    this.go(this.current + 1);

};

PageSlide.prototype.prev = function() {

    this.go(this.current - 1);

};

//重置方法,用于初始化以及当前页面的重置

PageSlide.prototype.reset = function() {

    var width = this.width;

    var height = this.height;

    var swipe = this.swipe;

    var current = this.getCurrent();

    var prev = current.previousElementSibling;

    var next = current.nextElementSibling;

    this.setCurrent(current);

    prev && (this['set' + swipe](prev, -(swipe === 'X' ? width : height)));

    next && (this['set' + swipe](next, swipe === 'X' ? width : height));

}

//去往下一或上一页面的go方法

PageSlide.prototype.go = function(i) {

    var onFinish = this.options.onFinish;

    var current = this.getCurrent();

    var total = this.$el.childElementCount;

    var target = this.$el.children[i];

    var d = i < this.current ? -1 : 1;

    if (i === this.current || i < 0 || i >= total) return;

    if (onFinish && (typeof onFinish === 'function')) onFinish.call(this, i);

    // 滑动完成调用方法

    typeof this.options.tranSetionEnd ==='function' && this.options.tranSetionEnd.call(this);

    this.current = i;

    this['set' + this.swipe](current, -d * (this.swipe === 'X' ? this.width : this.height)); //问题所在

    this.setCurrent(target, i);

    this.finish(current, target);

};

//滑动完成后删除当前页面.play标记以及为下一页面添加.play标记

PageSlide.prototype.finish = function(curr, target) {

    this.flag = null;

    setTimeout(function() {

        curr && curr.classList.remove('play');

        target && target.classList.add('play');

    }, 3e2);

};

//直达任意页面的方法

/*直达某一页面的方法, 因为个人研究的需要,写了这个方法,要从任意页面开始滑动依然能保持正常的滑动体验,就需要将直达页面的前面所有页面的translate3d参数都设置为(0,-height,0)  */

PageSlide.prototype.direct = function(i){

    if(i&&typeof(i)==='number'){

        this.go(i);

        for(var j = 0; j< i ;j++) {

            this['set' + this.swipe](this.$el.children[j], -1 * (this.swipe === 'X' ? this.width : this.height));      

            };

    }

    else  return;

};

  // 传参

document.addEventListener('touchmove', function(e) {

  e.preventDefault();

});

var pages = new PageSlide(document.querySelector('.pages'), 'Y', {

  tranSetionEnd: function() {

    console.log(this.current);

  }

});

转载于:https://www.cnblogs.com/yangwan/p/10307441.html

http://www.jmfq.cn/news/5218309.html

相关文章:

  • 杭州做兼职网站建设/市场营销七大策略
  • 做响应式网站的物流/seo是什么字
  • 红花岗区住房和城乡建设局网站/进一步优化落实
  • 基于互联网怎样做网站推广/省好多会员app
  • html5网站开发框架/友情链接联盟
  • 莎娜琳官方网站做水/备案域名购买
  • 网站建设公司有/百度售后服务电话
  • 网站建设 英文/郑州seo技术博客
  • 教研网站建设方案/湖北seo诊断
  • 做国外搞笑网站/用模板快速建站
  • 小红书关键词优化/宁波seo外包服务
  • 在linux上做网站搭建/研究生培训机构排名
  • 客户做网站要退款/会员制营销方案
  • 北京软件技术有限公司/衡水网站优化推广
  • 做日本暖暖小视频网站/超级优化
  • 做网站推广员需要/seo网络贸易网站推广
  • 风水网站建设的策划书/黑帽seo联系方式
  • 罗岗网站建设公司/如何创建网站平台
  • 北京网站建设最便宜的公司哪家好/精准引流的网络推广
  • 梵讯企业网站建设/迅雷磁力链bt磁力天堂
  • 有那些做任务的网站/360上网安全导航
  • 互联网大会官网/常州seo关键词排名
  • 网页微信版会痕迹吗/赣州seo公司
  • 完善网站建设的方法/旺道网站排名优化
  • 有那个网站可以做任务赚钱吗/seo排名优化培训网站
  • 湖南长沙网站制作/自己怎么开发app软件
  • 鞍山网站设计/网络运营团队
  • 电商网站的建设/网络销售平台有哪些软件
  • 钟落潭有没有做网站的/软文代写平台
  • 宁夏做网站好的公司/游戏特效培训机构排名