d3实现文字蛇形动画效果
代码语言:html
所属分类:布局界面
代码描述:d3实现文字蛇形动画效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
html {
line-height: 1.15;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
font-family: "Lato", sans-serif;
}
body {
margin: 0;
overflow-x: hidden;
}
section {
display: block;
}
svg {
overflow: visible;
}
section {
background-color: white;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin-top: 0;
margin-bottom: 0.5rem;
font-weight: 300;
}
#viz-word-snake {
font-size: 14px;
white-space: pre;
cursor: default;
width: 700px;
margin: 0 auto;
}
.circle-path {
fill: none;
pointer-events: none;
}
.node .circle-background {
fill: none;
pointer-events: all;
cursor: pointer;
}
.circle-center-translation {
font-family: "Lato", sans-serif;
font-size: 0.8em;
font-weight: 400;
text-anchor: middle;
pointer-events: none;
}
.circle-center-original {
font-family: "Dancing Script", cursive;
font-size: 1.7em;
text-anchor: middle;
pointer-events: none;
}
.circle-center-language {
font-family: "Lato", sans-serif;
font-size: 0.8em;
font-weight: 400;
font-style: italic;
text-anchor: middle;
pointer-events: none;
}
.circle-path-legend {
font-family: "Lato", sans-serif;
font-size: 0.8em;
pointer-events: none;
}
.circle-path-text {
font-family: "Dancing Script", cursive;
font-size: 1.1em;
pointer-events: none;
}
</style>
</head>
<body translate="no">
<div id="viz-word-snake"></div>
<script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/d3.v5.js"></script>
<script >
var darkgrey = "#161616",
middlegrey = "#a7a7a7",
lightgrey = "#afafaf";
var languageMap = [];
languageMap["de"] = "German";
languageMap["es"] = "Spanish";
languageMap["fr"] = "French";
languageMap["it"] = "Italian";
languageMap["ja"] = "Japanese";
languageMap["nl"] = "Dutch";
languageMap["pl"] = "Polish";
languageMap["pt"] = "Portuguese";
languageMap["ru"] = "Russian";
languageMap["tr"] = "Turkish";
languageMap["all"] = "All languages";
var divWidth = parseInt(d3.select("#viz-word-snake").style("width"));
var margin = {
top: 10,
right: 10,
bottom: 40,
left: 10
};
var width = divWidth - margin.left - margin.right;
var height = width;
console.log(divWidth,width,height)
//SVG container
var svg = d3.select("#viz-word-snake").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + (margin.left) + "," + (margin.top) + ")");
var parseTime = d3.timeParse("%Y-%m-%d"); // timeParse is added in version v4
var angle = 35 * Math.PI / 180;
var radius = 75;
var newXmargin = margin.left;
var n;
//Round number to 2 behind the decimal
function round2(num) {
return (Math.round((num + 0.00001) * 100) / 100);
}//round2
function calculateGrid() {
//How many circles fir in one "row"
var s = width / Math.cos(angle);
var numCircle = Math.min(4, Math.floor(s / (2 * radius)));
//I don't want 1 circle
if (numCircle === 1) numCircle = 2;
//If it's not an exact fit, make it so
radius = Math.min(radius, round2((s / numCircle) / 2));
//Save the x-locations if each circle
var xLoc = new Array(numCircle);
for (var i = 0; i < numCircle; i++) {
xLoc[i] = round2((1 + 2 * i) * radius * Math.cos(angle));
}//for i
//Locations for the textPath
var xLocArc = new Array(numCircle + 1);
for (var i = 0; i <= numCircle; i++) {
xLocArc[i] = round2(2 * i * radius * Math.cos(angle));
}//for i
//New wid.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0