1.创建项目

#使用simple模板
vue init webpack-simple vue-svg
#安装依赖
cd vue-svg/
npm i
#安装d3
npm i d3 --save

2.代码

重复性代码未做整理.

App.vue

<template>
<div id="app">
<svg id="svg"></svg>
</div>
</template> <script>
import * as d3 from "d3"; export default {
name: "app",
data() {
return {
msg: "Welcome to Your Vue.js App"
};
},
methods: {
draw() {
console.log(d3);
const svg = d3.select("#svg"); const face = svg
.append("circle")
.attr("r", 200)
.attr("fill", "yellow")
.attr("cx", 200)
.attr("cy", 200)
.attr("stroke", "black");
const leftEye = svg
.append("circle")
.attr("r", 30)
.attr("fill", "black")
.attr("cx", 100)
.attr("cy", 140);
const rightEye = svg
.append("circle")
.attr("r", 30)
.attr("fill", "black")
.attr("cx", 300)
.attr("cy", 140);
const leftEyebrow = svg
.append("rect")
.attr("x", 70)
.attr("y", 80)
.attr("height", 10)
.attr("width", 60)
.transition()
.duration(1000)
.attr("y", 60)
.transition()
.duration(1000)
.attr("y", 80);
const rightEyebrow = svg
.append("rect")
.attr("x", 270)
.attr("y", 80)
.attr("height", 10)
.attr("width", 60)
.transition()
.duration(1000)
.attr("y", 60)
.transition()
.duration(1000)
.attr("y", 80);
const mouth = svg
.append("path")
.attr(
"d",
d3.arc()({
innerRadius: 140,
outerRadius: 150,
startAngle: Math.PI / 2,
endAngle: (Math.PI * 3) / 2
})
)
.attr("transform", "translate(200,200)");
}
},
mounted() {
this.draw();
}
};
</script> <style>
#app {
height: 500px;
width: 100%;
}
#svg {
height: 100%;
width: 100%;
}
* {
margin: 0;
padding: 0;
}
</style>

3.打包

#编译
npm run build
#全局安装server
npm i http-server -g
#运行server, 当前目录作为server的根目录
http-server

svg make a face的更多相关文章

  1. 【Web动画】SVG 实现复杂线条动画

    在上一篇文章中,我们初步实现了一些利用基本图形就能完成的线条动画: [Web动画]SVG 线条动画入门 当然,事物都是朝着熵增焓减的方向发展的,复杂线条也肯定比有序线条要多. 很多时候,我们无法人工去 ...

  2. 【Web动画】SVG 线条动画入门

    通常我们说的 Web 动画,包含了三大类. CSS3 动画 javascript 动画(canvas) html 动画(SVG) 个人认为 3 种动画各有优劣,实际应用中根据掌握情况作出取舍,本文讨论 ...

  3. SVG:textPath深入理解

    SVG的文本可以沿着一条自定义的Path来排布,比如曲线.圆形等等,使用方式如下所示(来源MDN): <svg viewBox="0 0 1000 300" xmlns=&q ...

  4. SVG:linearGradient渐变在直线上失效的问题解决方案

    SVG开发里有个较为少见的问题. 对x1=x2或者y1=y2的直线(line以及path),比如: <path d="M200,10 200,100" stroke=&quo ...

  5. HTML5_05之SVG扩展、地理定位、拖放

    1.SVG绘图总结: ①方法一:已有svg文件,<img src="x.svg">  方法二:<body><svg></svg>&l ...

  6. HTML5_04之SVG绘图

    1.关于Canvas绘制图像: 问题:需要绘制多张图片时,必须等待所有图片加载完成才能开始绘制:而每张图片都是异步请求,彼此没有先后顺序,哪一张先加载完成完全无法预测: 方案: var progres ...

  7. 关于SVG的viewBox

    在SVG中,通过svg标记的 width和height可以规定这段SVG代码所表达的数据在绘制时所占用的空间大小 如下代码svg设置了宽度与高度,rect同样,所以结果自然是全屏 <svg wi ...

  8. JavaScript权威设计--jQuery,Ajax.animate,SVG(简要学习笔记二十)[完结篇]

    1.$和jquery在全局命名空间中定义的唯一两个变量.   2.jquery是工厂函数,不是构造函数.他返回一个新创建的对象.   3.jquery的四种调用方式:     <1>传递C ...

  9. Notes:SVG(4)基于stroke-dasharray和stroke-dashoffset圆形进度条

    stroke-dasharray:定义描边的虚线长度,如果提供奇数个,则会自动复制该值成偶数 stroke-dashoffset:定义虚线描边的偏移量(在路径开始的前面,看不到) 实现如下所示 svg ...

  10. Notes:SVG(3)---滤镜和渐变

    SVG滤镜使用filter标签来定义,该标签必须嵌套在defs元素里面,并且必须指定一个ID,以供引用. 在 SVG 中,可用的滤镜有: feBlend feColorMatrix feCompone ...

随机推荐

  1. 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0

    Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2806   Accepted:  ...

  2. bzoj2442

    题解: 单调队列+dp f[i]=max(f[j-1]+sum[i]-sum[j]) 然后维护f[j-1]-sum[j]单调性 代码: #include<bits/stdc++.h> us ...

  3. 在Indicator中添加动态Checkbox,无需绑定数据源,支持全选 - Ehlib学习(二)

    先做设置 DBGrideh属性设置: IndicatorOptions = [gioShowRowIndicatorEh, //小三角指示 gioShowRecNoEh, //数据源行号 gioSho ...

  4. U盘安装linix

    首先制作u盘启动器. 然后在电脑上使用UltraISO将你的安装的linix系统刻录到u盘上 在放入一份linix系统在u盘更目录 boot页面u盘启动.选择 第二次没有放入系统在u盘根目录出现这个: ...

  5. Spring Boot 报错:Error creating bean with name 'entityManagerFactory' defined in class path resource

    spring boot 写一个web项目,在使用spring-data-jpa的时候,启动报如下错误: Error starting ApplicationContext. To display th ...

  6. NOIP 2005 校门外的树

    #include<iostream> #include<cstring> using namespace std; int a[10005]; int main() { mem ...

  7. linux系统报错日志学习

    linux本身会自动记录系统报错日志:/var/log/messages 这个日志记录,我是在什么时候发现其强大的作用的呢?它有点像我们使用php脚本开发接口的时候技术员在重要地方打日志的效果,方便技 ...

  8. Linux学习系列之Nginx调优实战

    Nginx配置文件性能微调 全局的配置 user www-data; pid /var/run/nginx.pid; worker_processes auto; worker_rlimit_nofi ...

  9. 关于OkHttp–支持SPDY协议的高效HTTP库 com.squareup.okhttp

    转载:http://liuzhichao.com/p/1707.html OkHttp–支持SPDY协议的高效HTTP库 柳志超博客 » Program » Andriod » OkHttp–支持SP ...

  10. WIN10下搭建react-native开发Android环境

    最近公司要求使用react-native进行移动端开发,据说macOS上开发坑会少的多,但我们是windows,莫法,直接抗吧!周末配置环境遇到很多问题,谨以此文做个记录... 准备 安装Chocol ...