好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

移动web:翻页场景动画_html/css_WEB-ITnose

在移动web,特别是在微信中,经常看到一种翻页动画效果,也称为场景动画。

一页一页的翻过,像在看书,每页的内容以各种 "炫酷" 的效果出现在你的眼里,配上一首动听的音乐,你有没有喜欢上呢。

这里没有音乐,没有炫酷的出场,只有实实在在的翻页。z

先看看效果( 如果不能查看 复制下面的代码保存在本地查看 )

一生就这么一次,

谈一场以结婚为目的的恋爱吧。

不再因为任性而不肯低头,

不再因为固执而轻言分手。

最后地坚信一次,一直走,就可以到白头。

惟愿这一生,执子之手,与子偕老。

你敢天长,我就敢地久。

深思熟虑之后我们决定

为爱情做出重要的延续

邀请您一起见证

先贴上代码, 仅供参考

/** * LBS slidePage 绝对定位方式 支持WP * Date: 2014-11-20 * =================================================== * opts.el 外围包裹容器/滑动事件对象(一个字符串的CSS选择器或者元素对象) * opts.index 索引(默认0) 指定显示哪个索引的页 * opts.current    当前页添加的类名(默认'current') * opts.navShow 是否需要导航指示 默认false不需要  * opts.navClass 导航指示容器的类名 方便设置样式 (默认'slide-nav')  * opts.auto 是否自动播放 默认false * opts.delay 自动播放间隔时间 默认5000(单位毫秒) 自动播放时有效 * opts.locked 是否锁定头尾滑动  默认false 如果开启则不能使用自动播放 * opts.effect 动画效果(平移=translate 缩放=scale 重叠=overlap) 默认平移 * opts.duration 动画持续时间 默认300(单位毫秒)  * opts.minScale 动画效果为缩放时的最小缩放比率(0 ~ 1) 1为没有缩放效果 默认0.5 * opts.start 手指按下时 执行函数 * opts.move 手指移动中 执行函数 * opts.end 手指收起后 执行函数 * =================================================== * this.box 包裹页的容器对象 * this.index 当前索引 * this.length 有多少页 最后一页的索引为 this.length-1 * this.play 调用自动播放的方法  * this.stop 清除自动播放的方法 * this.up 手动调用向上滑动翻页的方法 方便增加点击按钮时调用 * this.down 手动调用向下滑动翻页的方法 * =================================================== **/;(function() {    window.slidePage = function(opts) {        opts = opts || {};        if (opts.el === undefined) return;        this.box = typeof opts.el === 'string' ? document.querySelector(opts.el) : opts.el;        this.pages = this.box.children;        this.length = this.pages.length;        if (this.length   this.length - 1) opts.index = 0;        this.body = document.getElementsByTagName('body')[0];        this.nav = null;        this.navs = [];        this.navShow = !!opts.navShow || false;        this.navClass = opts.navClass || 'slide-nav';        this.index = this.oIndex = opts.index || 0;        this.current = opts.current || 'current';        this.locked = !!opts.locked || false;        this.auto = !!opts.auto || false;        this.auto && (this.delay = opts.delay || 5000);        this.effect = opts.effect || 'translate';        this.duration = opts.duration || 300;        this.minScale = opts.minScale || 0.5;        this.start = opts.start || function() {};        this.move = opts.move || function() {};        this.end = opts.end || function() {};        this.timer = null;        this.animated = true;        this.touch = {};        this.point = '';        this.init();    };    slidePage.prototype = {        init: function() {            this.navShow && this.createNav();            this.initSet();            this.bind();        },        createNav: function() {            var li = null,                i = 0;            this.nav = document.createElement('ul');            for (; i   1) return;                this.touch.disX = e.touches[0].pageX - this.touch.x;                this.touch.disY = e.touches[0].pageY - this.touch.y;            }            if (this.touch.fixed === '') {                if (Math.abs(this.touch.disY) > Math.abs(this.touch.disX)) {                    this.touch.fixed = 'up';                } else {                    this.touch.fixed = 'left';                }            }            if (this.touch.fixed === 'up') {                if (this.effect === 'scale') {                    this.scale = ((this.height - Math.abs(this.touch.disY)) / this.height).toFixed(3);                    this.scale   0) {                    if (this.locked && this.oIndex === 0) return;                    this.dis = -this.height;                    this.index = this.oIndex - 1;                    this.index   this.length - 1 && (this.index = 0);                    if (this.effect === 'scale') this.setOrigin(this.oIndex, 'center top');                }                if (this.nIndex !== undefined && this.nIndex !== this.index && this.nIndex !== this.oIndex) {                    this.pages[this.nIndex].style.display = 'none';                    this.pages[this.nIndex].style.zIndex = '';                    this.pages[this.nIndex].style.webkitTransform = this.pages[this.nIndex].style.transform = '';                }                this.nIndex = this.index;                this.pages[this.oIndex].style.zIndex = this.zIndex;                this.pages[this.index].style.zIndex = this.zIndex + 10;                this.setTransform(this.index, this.dis);                this.pages[this.index].style.display = 'block';                this.setTransform(this.index, this.touch.disY + this.dis);                if (this.effect === 'translate') this.setTransform(this.oIndex, this.touch.disY);                if (this.effect === 'scale') this.setScale(this.oIndex, this.scale);                this.move && this.move();            }        },        touchEnd: function(e) {            this.point = '';            if (this.index === this.oIndex) return;            if (this.touch.fixed === 'up') {                var Y = Math.abs(this.touch.disY);                if ((this.animated && Y > 10) || Y > this.height / 2) {                    this.slide();                } else {                    this.goback();                }                this.end && this.end();            }        },        css: function(o, n) {            return getComputedStyle(o, null)[n];        },        on: function(el, types, handler) {            for (var i = 0, l = types.length; i   this.length - 1 && (this.index = 0);            if (this.effect === 'scale') this.setOrigin(this.oIndex, 'center top');            this.animate();        },        down: function() {            this.dis = -this.height;            this.index--;            this.index  

和以前写的 图片切换 有许多共同的地方,整个翻页和图片切换原理都是类似的。

这个支持自动播放,三种翻页效果,限制头尾滑动等。

翻页动画,就是在一个容器内滑动, 在这个容器中 每次只显示一页,每一页都有一些css3动画效果的元素出现。

一个简单的HTML结构如下:

查看更多关于移动web:翻页场景动画_html/css_WEB-ITnose的详细内容...

  阅读:37次