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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
2026TECHFRESH畢業分享會 - 原生還是跨平台? App 開發踩坑實錄
line_developers_tw
PRO
0
1k
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
330
手塩にかけりゃいいってもんじゃない
ming_ayami
0
570
Bucharest Tech Week 2026 - Reinventing testing practices in the AI era
edeandrea
PRO
1
160
小さくはじめるSLI/SLO ~育てながら組織に定着させる実践知~ / Starting Small with SLI/SLOs: Building Adoption Through Continuous Growth
nari_ex
7
1.9k
日本 Fintech 未来予測レポート 2027〜2028年(手動編集版)
8maki
0
2.3k
【NRUG vol.18】なぜ多くのオブザーバビリティ導入は失敗するのか
nrug_member
0
130
FDE という解 ― 暗黙知と明示知をつなぐ、伴走型エンジニアリング ―
otanet
0
160
"何を作るか"を任される エンジニアは、どう育つのか
yutaokafuji
1
680
失敗を資産に変えるClaude Code
shinyasaita
0
650
2026TECHFRESH畢業分享會 - Lightning Talk - E起 See See : 電商推薦讀心術? 數據說了算
line_developers_tw
PRO
0
1k
SONiCで構築・運用する生成AI向けパブリッククラウドネットワーク ~実装編~
sonic
0
210
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
860
Faster Mobile Websites
deanohume
310
31k
Designing for humans not robots
tammielis
254
26k
AI: The stuff that nobody shows you
jnunemaker
PRO
8
710
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
65
55k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
190
Become a Pro
speakerdeck
PRO
31
6k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
240
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