现代浏览器基本支持CSS3,但是一些旧版本的浏览器还是需要添加前缀的。像box-shadowborder-radius这类属性,目前较新版本的浏览器都是不需要前缀的(包括IE9),但是,有些CSS3属性,例如渐变,前缀少不了,每次都需要像盖高楼一样堆叠CSS3代码,如下图:

.bg {width:400px;height:177px;margin:70px auto 0;padding-top:73px;position:relative;background-image:-webkit-linear-gradient(top,rgb(255,255,255),rgb(242,242,242));background-image:-moz-linear-gradient(top,rgb(255,255,255),rgb(242,242,242));background-image:-ms-linear-gradient(top,rgb(255,255,255),rgb(242,242,242));background-image:-o-linear-gradient(top,rgb(255,255,255),rgb(242,242,242));background-image:linear-gradient(top,rgb(255,255,255),rgb(242,242,242));box-shadow:0 3px 3px rgba(21,62,78,0.8);
}

代码效果如下,点击这里查看演示:

那么如何省去CSS3中前缀“-moz”、“-webkit”、“-o”、“-ms”呢,需要使用prefixfree脚本来实现。

一,下面说说如何使用prefixfree脚本:

下面是官方网站截图:

那么如何使用该脚本呢?下面是截至官网的两个DEMO,使用环境为Chrome,所以建议下载最新版的Chrome浏览器对演示地址进行浏览,希望能对使用提供帮助:

有前缀官方DEMO,未使用prefixfree脚本:

@-webkit-keyframes rotate {from { -webkit-transform: rotate(15deg) }to { -webkit-transform: rotate(375deg) }
}.download {position: absolute;top: 2em;left: 1em;width: 6em;height: 6em;padding: 1em 0;background: #80A060;background-image: linear-gradient(90deg, transparent, rgba(10,0,0,.3)),linear-gradient(transparent, transparent);color: white;line-height: 1;font-size: 140%;text-align: center;text-decoration: initial;text-shadow: .08em .08em .2em rgba(0,0,0,.6);border-radius: 50%;box-shadow: .1em .2em .4em -.2em black;box-sizing: border-box;-webkit-transform: rotate(15deg);-webkit-animation: rotate;cursor: -webkit-zoom-in;
}:read-write {}

在Chrome中的效果如下图, 如你使用的是最新版的Chrome浏览器也可以点击这里,查看演示页面:

无前缀官方DEMO,使用prefixfree.js脚本后能达到同意的效果:

<script src="prefixfree.min.js" type="text/javascript"></script><!--引入prefixfree脚本-->
<style>
@keyframes rotate {from { transform: rotate(15deg) }to { transform: rotate(375deg) }
}.download {position: absolute;top: 2em;left:1em;width: 6em;height: 6em;padding: 1em 0;background: #80A060;background-image: linear-gradient(90deg, transparent, rgba(10,0,0,.3)),linear-gradient(transparent, transparent);color: white;line-height: 1;font-size: 140%;text-align: center;text-decoration: initial;text-shadow: .08em .08em .2em rgba(0,0,0,.6);border-radius: 50%;box-shadow: .1em .2em .4em -.2em black;box-sizing: border-box;transform: rotate(15deg);animation: rotate;cursor: zoom-in;
}:read-write {}
</style>

在Chrome中的效果如下图, 能达到使用前缀同样的效果,如你使用的是最新版的Chrome浏览器也可以点击这里,查看演示页面:

二,下面介绍Animatable 动画效果应用,该应用需与prefixfree脚本一起使用:

话不多说直接上截图吧:

是不是有种百花齐放的感觉呢!

下面是官方演示地址:

http://leaverou.github.io/animatable/

如网页响应慢的话,可以查看下面的演示的:

http://www.li-cheng.cn/demo/animatable-master/index.html

Animatable项目页面动画效果的批量实现原理如下:
1. 遍历页面上每个含有data-property属性的a元素;
2. 根据dom元素上的data-property值,form值和to值组装无前缀的CSS3 animate样式代码;
3. 以style节点元素的形式将组装的CSS代码append到head标签中,因页面调用了prefixfree.js脚本,于是各个浏览器下的animate CSS被渲染,效果呈现。

以下是源码介绍,:

function $(expr, con) { return (con || document).querySelector(expr); }
function $$(expr, con) { return [].slice.call((con || document).querySelectorAll(expr)); }var css = [];//遍历页面中 a标签中含有 data-property 属性的所有元素
$$('a[data-property]').forEach(function(el, i){var property = el.getAttribute('data-property'),from = el.getAttribute('data-from'),to = el.getAttribute('data-to');var id = property, i = 1;while(document.getElementById(id)) {id = property + '/' + ++i;}el.id = id;el.href = '#' + id;el.title = property + ' from ' + from + ' to ' + to;var selector = '#' + id.replace(/([^\w-])/g, '\\$1'),ident = id.replace(/([^\w-])/g, '-');//创建css3样式代码,push到css数组中css.push('@keyframes ' + ident + '{','from{' + property + ':' + from + '}','to{' + property + ':' + to + '}}',selector + ' { animation: ' + ident + ' 1s infinite alternate;' + property + ':' + from + '}');
});var style = document.createElement('style');
style.textContent = css.join('\r\n');
StyleFix.styleElement(style);
document.head.appendChild(style);  //在页面中添加 style标签 setTimeout(onhashchange = function() {var target = location.hash? $(location.hash.replace(/([^\w-#])/g, '\\$1')) : null;if(!target) {document.body.className = 'home';return;}document.body.className = 'in-page';var info = $('#info'),previous = target.previousElementSibling,next = target.nextElementSibling,author = target.getAttribute('data-author') || 'leaverou';$('h1', info).innerHTML = target.getAttribute('data-property');$('dd:first-of-type', info).innerHTML = target.getAttribute('data-from');$('dd:nth-of-type(2)', info).innerHTML = target.getAttribute('data-to');$('dd:nth-of-type(3)', info).innerHTML = '<a href="http://twitter.com/' + author + '" target="_blank"><img src="http://twitter.com//api/users/profile_image?screen_name=' + author + '&size=mini"/>@' + author + '</a>';$('a[title="Previous"]', info).setAttribute('href', '#' + (previous? previous.id : ''));$('a[title="Next"]', info).setAttribute('href', '#' + (next? next.id : ''));setTimeout(function() {if(2*target.offsetLeft + target.offsetWidth < innerWidth) {info.style.left = target.offsetLeft + target.offsetWidth + 30 + 'px';}else {info.style.left = target.offsetLeft - info.offsetWidth - 30 + 'px';}info.style.top = target.offsetTop + 'px';}, 10);
}, 50);onkeyup = function(evt) {var key = evt.keyCode;switch (key) {case 27:location.hash = '';break;case 37:case 38:location.hash = location.hash? $('a[title="Previous"]').hash : $('a[data-property]:last-child').hash;break;case 39:case 40:location.hash = location.hash? $('a[title="Next"]').hash : $('a[data-property]:first-child').hash;}
};

文章参考了如下地址,有兴趣的可以点击查看:

http://www.zhangxinxu.com/wordpress/2011/11/css3-prefixfree-js-animatable/

prefixfree官方地址:

http://leaverou.github.io/prefixfree/

Animatable官方地址:

http://leaverou.github.io/animatable/

CSS3无前缀脚本prefixfree.js与Animatable使用相关推荐

  1. CSS3无前缀脚本prefixfree.js与Animatable使用介绍

    要求 必备知识 本文要求基本了解 JAVASCRIPT 和 和 CSS3 基本知识. 运行环境 桌面端:IE9 +,Opera 10+,火狐3.5 +,Safari 4+和Chrome浏览器;移动端: ...

  2. CSS3无前缀脚本prefixfree.js及Animatable介绍

    一.引导之言 虽然现代浏览器支持CSS3,但是一些过往的版本或是目前有些CSS3属性的应用还是离不开前缀的.像box-shadow, border-radius这类属性,目前较新版本的浏览器都是不需要 ...

  3. css3禅意花园脚本_如何创建无脚本CSS3工具提示

    css3禅意花园脚本 啊...工具提示. 它们可以解决您的许多支持问题,或者仅向用户提供一些提示. 如今,有大量使用工具提示的网站和应用程序,但是...有没有更好的方法来实现它们? 我很高兴地说,有一 ...

  4. python3 字符串前字母(无前缀,前缀u,前缀b,前缀r)含义

    字符串前加 u 后面字符串以 Unicode 格式 进行编码,一般用在中文字符串前面,防止因为源码储存格式问题,导致再次使用时出现乱码. 字符串前加 b python3.x里默认的str是(py2.x ...

  5. html5 无插件视频播放器,多功能流媒体播放器网页无插件直播EasyPlayer.js如何实现播放完自动循环播放...

    原标题:多功能流媒体播放器网页无插件直播EasyPlayer.js如何实现播放完自动循环播放 EasyPlayer-Android播放器是一款可针对RTSP.RTMP.RTSP&RTMP协议进 ...

  6. 18种各式各样的loading,纯html5+css3无图片

    网友总结的18种各式各样的loading,纯html5+css3无图片,我再次整理下 <!DOCTYPE html> <html lang='zh_CN'> <head& ...

  7. 【无标题】把js脚本藏在书签里 一键运行代码

    如果经常针对某网站执行重复的步骤,比如登录.填表.复制内容等操作,可以自定义一段JS脚本,每次只要执行这段脚本代码就能自动完成操作. 但是一般的浏览器直接执行JS脚本并不方便,需要复制粘贴脚本代码,最 ...

  8. 低版本浏览器支持css3 Media查询的方法, ie6-ie8 不支持css3 的时候用respond.js,html5shiv.js 【非常实用哦】。。。。。。。。。。。。...

    Respond.js 是一个快速.轻量的 polyfill,用于为 IE6-8 以及其它不支持 CSS3 Media Queries 的浏览器提供媒体查询的 min-width 和 max-width ...

  9. 推荐轻量高效无依赖的开源JS插件和库

    为什么80%的码农都做不了架构师?>>>    在这里维持一个持续更新的地方 图片 baguetteBox.js - 是一个简单易用的响应式图像灯箱效果脚本.demo Lightga ...

最新文章

  1. Redis、MongoDB、Memcache的比较
  2. RouterOS和艾泰路由建立ipsec ×××连接
  3. python 仪表盘数据显示_跟小白学Python数据分析——绘制仪表盘
  4. Android资源分离,可分离Android操作系统报告:硬件环境检测文件(十)(分析)...
  5. spring mvc返回页面显示空白_Spring 框架基础(06):Mvc架构模式简介,执行流程详解...
  6. ASP.NET MVC 线程和并发
  7. 单例模式(singleton)解析例子
  8. vb使用字符串分隔字符串_为什么要使用字符串
  9. SIFT特征匹配及其实现
  10. oracle及操作系统对于文件大小的限制
  11. Unity连接MySQL数据库方法整合
  12. [安卓开发] Android 自己做双向手电筒 源代码
  13. 推荐这三款亲测好用的ai工具
  14. facenet生成自己的pairs.txt
  15. 2018年中国互联网企业百强榜单
  16. Android 之UI自适应解决方案
  17. java台球游戏设计原理_台球游戏的核心算法和AI(1)
  18. c语言数据类型及命名规则
  19. 年终总结——勤为容衰亦心满, 奋作平凡千椽梁!
  20. 字节跳动再“进攻”印度市场,口碑本就不尽人意,这次会顺利吗?

热门文章

  1. python 数据的基本类型(字符串)
  2. ubuntu 12.04 解压安装jdk
  3. Docker 初步认识
  4. JVM内存GC的骗局
  5. 数据库--循环语句:loop exit when/ end loop
  6. 解决Android中No resource found that matches android:TextAppearance.Material.Widget.Button.Inverse问题...
  7. 2015上半年软件设计师考点,难点3
  8. (三)ajax请求不同源之websocket跨域
  9. 求数组中的最大数,最小数。
  10. explain的讲解