Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
拉菲尔-让svg在飞一会
Search
w3cplus
November 25, 2012
Technology
620
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
拉菲尔-让svg在飞一会
SVG相关介绍
w3cplus
November 25, 2012
More Decks by w3cplus
See All by w3cplus
手淘互动动效探索
w3cplus
0
250
CSS Future
w3cplus
2
650
Web Animation
w3cplus
5
510
CSS3带来的变化
w3cplus
0
1.5k
Web重构之道
w3cplus
1
2.9k
Sass带来的变革
w3cplus
2
640
Responsive小试牛刀
w3cplus
3
570
CSS预处器——Sass、LESS和Stylus实践
w3cplus
0
400
http协议与缓存简述
w3cplus
5
540
Other Decks in Technology
See All in Technology
Control Planeで育てるBtoB SaaSの認証基盤 - SRE NEXT 2026
pokohide
1
950
AI時代における最適なQA組織の作り方
ymty
3
430
グローバルチームと挑むプロダクト開発
sansantech
PRO
1
160
オブザーバビリティ、本当に活用できてる? 〜API連携×生成AIで成熟度を自動評価〜
dmmsre
0
1.5k
デジタル・デザイン:次の50年を描く「進化する青写真」
y150saya
0
820
Terraform共通モジュールをチーム横断で“変えられる”運用へ ― リリースと適用の分離
kekke_n
0
1.2k
どうして今サーバーサイドKotlinを選択したのか
nealle
0
210
AWS Summit の片隅で、体育座りしながらコミュニティがにぎわう理由を考えた
k_adachi_01
2
350
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
190
AIで政治は変わるのか? — 中高生と考えたAI時代の民主主義(東海高校サタデープログラム)
eitarosuda
0
400
AI Driven AI Governance
pict3
0
160
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
150
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
3.1k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
How GitHub (no longer) Works
holman
316
150k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
370
New Earth Scene 8
popppiees
3
2.4k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
960
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Navigating Team Friction
lara
192
16k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Transcript
拉菲尔-让svg在飞一会 99 前端工程师 新浪微博@宇宙一片小囧
Svg是一个 标准! Svg是什么? 可缩放矢量图形(Scalable Vector Graphics,SVG)是基于可扩展标记语言 (XML),用于描述二维矢量图形的一种图 形格式。SVG由W3C制定,是一个开放标 准。 http://graphic.duapp.com/
怎样抖的? 抖的什么? Svg?Png?gif?bit64?
图像层面! Svg优点? 非常容易修改 SVG 是可伸缩的,尺寸更小 SVG 图像中的文本是可选的,同时也是可 搜索的(很适合制作地图)
可操纵性! Svg优点? 非常容易修改 http://jsbin.com/epiwul/7 SVG节点,事件绑定与动画,都不是问 题。。。 JavaScript和CSS自由操纵svg
基于未来的 图形图像算 法! Svg有什么用? 几乎所有高兼容性的图表库的底层库均为拉 斐尔。(数据可视化http://datavlab.org/) http://coding.smashingmagazine.com/2012 /01/16/resolution-independence-with-svg/ 面向未来的图形解决方案 响应式设计的最
佳伴侣 http://www.evernote.com/shard/s156/sh/31 d8e8a5-d90f-41e7-8b83- 96c0e32b1733/1ac9acb4f44140296276e9 6362e4117a
扯淡吧! 为什么不用Svg? 大家可能都不知道。。都去玩canvas了。。 http://raphaeljs.com 兼容性:不是问题。 基于dom的元素操作非常繁琐:不是问题
想学么! Raphaeljs 跨越时代的js库 无数的demo http://raphaeljs.com 开源,完全免费,学习成本不算特别高。。。 Icon http://raphaeljs.com/icons/
想学么! Raphaeljs 跨越时代的js库 <script src="http://cdnjs.cloudflare.com/ajax/libs/r aphael/2.0.0/raphael-min.js"> var paper = Raphael(50,
50, 500, 500); for (var i = 0; i <5; i++) { paper.circle(10 + 15 * i, 10, 10)//创建 circle(x,y,r)的圆 .attr({fill: "#000"})//设置属性 .data("i", i)//设置自定义属性 .click(function () {//绑定事件 console.log(this.attr('cx'),this.data('i')); }); http://jsbin.com/omajal/2
想学么! Raphaeljs 跨越时代的js库 attr方法 http://raphaeljs.com/reference.html#Eleme nt.attr Fill Stroke R Opacity
transform Cx Cy stroke-width Animate方法 Image方法 核心的path方法
想学么! Raphaeljs 跨越时代的js库 http://jsbin.com/omajal/10/edit // 创建画布 500 × 500 at
50, 50 var paper = Raphael(50, 50, 500, 500); paper.circle(200, 200, 10)//创建 circle(x,y,r)的圆 .attr({fill: "red",stroke:'blue','stroke- width':10,opacity:0.2,})//设置属性 继续 attr({cx:120,cy:400,r:50} http://jsbin.com/omajal/13/edit
想学么! Raphaeljs 跨越时代的js库 http://jsbin.com/omajal/10/edit // 创建画布 500 × 500 at
50, 50 var paper = Raphael(50, 50, 500, 500); paper.circle(200, 200, 10)//创建 circle(x,y,r)的圆 .attr({fill: "red",stroke:'blue','stroke- width':10,opacity:0.2,})//设置属性 继续 attr({cx:120,cy:400,r:50} http://jsbin.com/omajal/13/edit
想学么! Raphaeljs 跨越时代的js库 // 创建画布 500 × 500 at 50,
50 var paper = Raphael(50, 50, 500, 500); //Paper.rect(x, y, width, height, [r]) paper.rect(0, 0, 1000, 400, 10).attr({ stroke : "none", fill : "0-#fff-#f00:20- #000" }); http://jsbin.com/omajal/15/edit 0指的是0度,也指的是从左到右渐变(90 从下到上 180从右到左,270从上到下) 每个-指的一个颜色节点。后面加冒号指的 是百分比 上面的意思是 从左到右,#fff渐变到 #f00 渐变到20%,之后#f00渐变到#000, 从20%渐变到100%
想学么! Raphaeljs 跨越时代的js库 r.circle(100, 100, 200).attr({ stroke : "none", fill
: "r(0.5, 0.5)black:20- red:70" }); http://jsbin.com/omajal/16/edit 径向渐变只支持圆与椭圆!
想学么! Raphaeljs 跨越时代的js库 r.circle(100, 100, 200).attr({ stroke : "none", fill
: "r(0.5, 0.5)black:20- red:70" }); http://jsbin.com/omajal/16/edit 径向渐变只支持圆与椭圆!
想学么! Raphaeljs 跨越时代的js库 attr的transform属性,非常强大。。 transform: “t100,100″ 表示移动相对距离 x100,y100 transform: “r30,100,100″表示以100,100
为中心旋转30度 transform: “s2,1,300,300″ 表示以300, 300为起始点,放大2倍 缩放一次 注意个参 数的对应。 若r s未指定参数,默认为中心点 http://jsbin.com/omajal/17/edit http://raphaeljs.com/reference.html#Eleme nt.transform
想学么! Raphaeljs 跨越时代的js库 attr的transform属性,非常强大。。 transform: “t100,100″ 表示移动相对距离 x100,y100 transform: “r30,100,100″表示以100,100
为中心旋转30度 transform: “s2,1,300,300″ 表示以300, 300为起始点,放大2倍 缩放一次 注意个参 数的对应。 若r s未指定参数,默认为中心点 http://jsbin.com/omajal/17/edit http://raphaeljs.com/reference.html#Eleme nt.transform
想学么! Raphaeljs 跨越时代的js库 animate var paper = Raphael(50, 50, 500,
500); paper.circle(320, 240, 60).animate({ fill : "#223fa3", stroke : "#000", "stroke-width" : 80, "stroke-opacity" : 0.5, 'cx':200, 'r':100 }, 2000); http://jsbin.com/omajal/18/edit http://raphaeljs.com/reference.html#Eleme nt.animate
想学么! Raphaeljs 跨越时代的js库 高级animate http://jsbin.com/omajal/19/edit 支持回调函数,支持缓动 批量操作的技巧:set() 可以用push 添加进去。 http://raphaeljs.com/reference.html#Eleme
nt.animate
想学么! Raphaeljs 跨越时代的js库 高级animate http://jsbin.com/omajal/19/edit http://raphaeljs.com/reference.html#Eleme nt.animate
想学么! Raphaeljs 跨越时代的js库 核心方法 path() * M = moveto *
L = lineto * H = horizontal lineto * V = vertical lineto * C = curveto * S = smooth curveto * Q = quadratic Belzier curve * T = smooth quadratic Belzier curveto * A = elliptical Arc * Z = closepath
想学么! Raphaeljs 跨越时代的js库 核心方法 path() * M = moveto *
L = lineto * H = horizontal lineto * V = vertical lineto * C = curveto * S = smooth curveto * Q = quadratic Belzier curve * T = smooth quadratic Belzier curveto * A = elliptical Arc * Z = closepath (closePath)
想学么! Raphaeljs 跨越时代的js库 核心方法 path() 画直线 http://jsbin.com/omajal/20/edit var paper =
Raphael(50, 50, 500, 500); paper.circle(10, 200, 2).attr({fill: "#000"}) paper.path("M10 200L100 200") paper.circle(100, 200, 2).attr({fill: "#000"}) http://jsbin.com/omajal/21/edit paper.path("M10 200L100 200L200 300L300 380 400 420") 折线图所有的ok!
想学么! Raphaeljs 跨越时代的js库 核心方法 path() 如何封装一个自己的图表库? Option Data Position http://jsbin.com/omajal/22/edit
想学么! Raphaeljs 跨越时代的js库 核心方法 path() 画曲线 http://jsbin.com/omajal/24/edit
想学么! Raphaeljs 跨越时代的js库 核心方法 path() 画曲线 http://jsbin.com/omajal/27/edit http://jsbin.com/omajal/32/edit
想学么! Raphaeljs 跨越时代的js库 核心方法 path() 画贝塞尔曲线 http://jsbin.com/omajal/29 贝塞尔曲线 http://cubic-bezier.com/#.17,.67,.83,.67 ["C",
ax, ay, bx, by, zx, zy] http://jsbin.com/omajal/34/edit
想学么! Raphaeljs 跨越时代的js库 学习资料: 贝塞尔曲线 http://cubic-bezier.com/#.17,.67,.83,.67 http://raphaeljs.com/ http://blog.csdn.net/hfahe/article/details/76 61494
谢谢! W3CPLUS 99 javascript make the world beautiful @宇宙一片小囧 Q&A