本次案例我们分析一下数据可视化页面最常见的热点图是如何实现的,其原理并不复杂,只需要用到CSS3动画属性 animation 以及 @keyframe 关键帧即可,重点是向外扩散的环如何布局比较合适,以及每个环怎么扩散何时扩散比较合适。
源码我已经上传到了资源里,想拿来学习引用的小伙伴直接下载即可,没有会员的可以私聊我 “大数据热点图” 免费获取,下方是源码的资源链接
原理分析我们分为热点的布局分析与热点向外扩散的动画实现的分析
- 布局我们那单独的一个城市分析,例如地图中北京的 ,其由一个类名为city1的最外层盒子来添加定位以定到目标城市位置,其不设置宽高,大小完全由中心点撑起(即第二个类名为center的盒子) ,波纹其实是有三个圈圈组成的,最开始是完全重合的,用中心小算法来保证其永远是围绕center来扩散的。
<div class="city1"> <div class="center1"></div> <p class="bj">Beijing</p> <div class="bw1"></div> <div class="bw2"></div> <div class="bw3"></div> </div>
- 波纹的样式添加我们采用了属性选择器 .city1 div[class^="bw"],即选择父类city1里面类名以bw开头的所有子div标签
.city1{ position: absolute; top: 370px; right: 403px; color: aliceblue; } .center1{ width: 5px; height: 5px; background-color: rgb(255, 255, 255); box-shadow: 0 0 12px 2px #fff; border-radius: 50%; } .city1 div[class^="bw"]{ position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 5px; height: 5px; box-shadow: 0 0 7px #fff; border-radius: 50%; animation: scla 3s linear infinite; } .map .city1 div.bw2{ animation-delay: 1s; } .map .city1 div.bw3{ animation-delay: 2s; }
- 本次添加的关键帧为:0%的时候波纹是完全不透明的,50%的时候宽高均变大为105px,即圈圈在总动画时间50%的时候要从宽高5px扩散到宽高105px,然后变为半透明状态。再下一个是100%的时候,扩散到宽高150px,并变成完全不透明。要给波纹添加属性:animation: scla 3s linear infinite; 含义为3s做完动画,匀速,并且无限循环
- 为了呈现出波纹一个接一个往外扩散而不是一起扩散,需要给第一个圈圈直接开始扩散,第二个圈圈第三个圈圈设置不同的 animation-delay 动画延迟,第二个设置为1s,第二个设置为2s,这样就可以呈现出一个接一个往外扩散了
/* @keyframes关键帧动画 */ @keyframes scla{ 0% { opacity: 1; } 50% { width: 105px; height: 105px; opacity: 0.5; } 100% { width: 150px; height: 150px; opacity: 0; } } .city3 div[class^="bw"]{ position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 5px; height: 5px; box-shadow: 0 0 7px #fff; border-radius: 50%; animation: scla 3s linear infinite; } .map .city3 div.bw2{ animation-delay: 1s; } .map .city3 div.bw3{ animation-delay: 2s; }
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: rgb(45, 45, 45);
}
.map{
position: relative;
width: 1400px;
height: 830px;
background-image: url(./img/QX3OPNW5qY.png);
background-repeat: no-repeat;
background-size: 100%;
margin: 0 auto;
}
.bj{
position: absolute;
top: 15px;
left: 10px;
font-size: 10px;
}
.Gambia{
position: absolute;
top: 15px;
left: 10px;
font-size: 10px;
color:rgb(255, 153, 153)
}
.Island{
position: absolute;
top: 15px;
left: 10px;
font-size: 10px;
}
/* 城市1 */
.city1{
position: absolute;
top: 370px;
right: 403px;
color: aliceblue;
}
.center1{
width: 5px;
height: 5px;
background-color: rgb(255, 255, 255);
box-shadow: 0 0 12px 2px #fff;
border-radius: 50%;
}
.city1 div[class^="bw"]{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 5px;
height: 5px;
box-shadow: 0 0 7px #fff;
border-radius: 50%;
animation: scla 3s linear infinite;
}
.map .city1 div.bw2{
animation-delay: 1s;
}
.map .city1 div.bw3{
animation-delay: 2s;
}
/* 城市2 */
.city2{
position: absolute;
top: 500px;
right: 703px;
color: aliceblue;
}
.center2{
width: 5px;
height: 5px;
background-color: rgb(255, 255, 255);
box-shadow: 0 0 12px 2px #fff;
border-radius: 50%;
}
.city2 div[class^="bw"]{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 5px;
height: 5px;
box-shadow: 0 0 7px rgb(255, 149, 149);
border-radius: 50%;
animation: scla1 3s linear infinite;
}
.map .city2 div.bw2{
animation-delay: 0.75s;
}
.map .city2 div.bw3{
animation-delay: 1.5s;
}
.map .city2 div.bw4{
animation-delay: 2.25s;
}
/* 城市3 */
.city3{
position: absolute;
top: 200px;
right: 1003px;
color: aliceblue;
}
.center3{
width: 5px;
height: 5px;
background-color: rgb(255, 255, 255);
box-shadow: 0 0 12px 2px #fff;
border-radius: 50%;
}
/* 属性选择器 正则表达式筛选bw开头类名 */
.city3 div[class^="bw"]{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 5px;
height: 5px;
box-shadow: 0 0 7px #fff;
border-radius: 50%;
animation: scla 3s linear infinite;
}
.map .city3 div.bw2{
animation-delay: 1s;
}
.map .city3 div.bw3{
animation-delay: 2s;
}
/* @keyframes关键帧动画 */
@keyframes scla{
0% {
opacity: 1;
}
50% {
width: 105px;
height: 105px;
opacity: 0.5;
}
100% {
width: 150px;
height: 150px;
opacity: 0;
}
}
@keyframes scla1{
0% {
opacity: 1;
}
50% {
width: 285px;
height: 285px;
opacity: 0.5;
}
100% {
width: 330px;
height: 330px;
opacity: 0;
}
}
</style>
</head>
<body>
<div class="map">
<div class="city1">
<div class="center1"></div>
<p class="bj">Beijing</p>
<div class="bw1"></div>
<div class="bw2"></div>
<div class="bw3"></div>
</div>
<div class="city2">
<div class="center2"></div>
<p class="Gambia">Gambia</p>
<div class="bw1"></div>
<div class="bw2"></div>
<div class="bw3"></div>
<div class="bw4"></div>
</div>
<div class="city3">
<div class="center3"></div>
<p class="Island">Island</p>
<div class="bw1"></div>
<div class="bw2"></div>
<div class="bw3"></div>
</div>
</div>
</body>
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我在MiniTest::Spec和Capybara中使用以下规范:find_field('Email').must_have_css('[autofocus]')检查名为“电子邮件”的字段是否具有autofocus属性。doc说如下:has_css?(path,options={})ChecksifagivenCSSselectorisonthepageorcurrentnode.据我了解,字段“Email”是一个节点,因此调用must_have_css绝对有效!我做错了什么? 最佳答案 通过JonasNicklas得到了答案:No
有没有办法在这个简单的get方法中添加超时选项?我正在使用法拉第3.3。Faraday.get(url)四处寻找,我只能先发起连接后应用超时选项,然后应用超时选项。或者有什么简单的方法?这就是我现在正在做的:conn=Faraday.newresponse=conn.getdo|req|req.urlurlreq.options.timeout=2#2secondsend 最佳答案 试试这个:conn=Faraday.newdo|conn|conn.options.timeout=20endresponse=conn.get(url
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
我有一个存储主机名的Ruby数组server_names。如果我打印出来,它看起来像这样:["hostname.abc.com","hostname2.abc.com","hostname3.abc.com"]相当标准。我想要做的是获取这些服务器的IP(可能将它们存储在另一个变量中)。看起来IPSocket类可以做到这一点,但我不确定如何使用IPSocket类遍历它。如果它只是尝试像这样打印出IP:server_names.eachdo|name|IPSocket::getaddress(name)pnameend它提示我没有提供服务器名称。这是语法问题还是我没有正确使用类?输出:ge
我想获取模块中定义的所有常量的值:moduleLettersA='apple'.freezeB='boy'.freezeendconstants给了我常量的名字:Letters.constants(false)#=>[:A,:B]如何获取它们的值的数组,即["apple","boy"]? 最佳答案 为了做到这一点,请使用mapLetters.constants(false).map&Letters.method(:const_get)这将返回["a","b"]第二种方式:Letters.constants(false).map{|c
我安装了ruby版本管理器,并将RVM安装的ruby实现设置为默认值,这样'哪个ruby'显示'~/.rvm/ruby-1.8.6-p383/bin/ruby'但是当我在emacs中打开inf-ruby缓冲区时,它使用安装在/usr/bin中的ruby。有没有办法让emacs像shell一样尊重ruby的路径?谢谢! 最佳答案 我创建了一个emacs扩展来将rvm集成到emacs中。如果您有兴趣,可以在这里获取:http://github.com/senny/rvm.el
假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit
我目前正在使用以下方法获取页面的源代码:Net::HTTP.get(URI.parse(page.url))我还想获取HTTP状态,而无需发出第二个请求。有没有办法用另一种方法做到这一点?我一直在查看文档,但似乎找不到我要找的东西。 最佳答案 在我看来,除非您需要一些真正的低级访问或控制,否则最好使用Ruby的内置Open::URI模块:require'open-uri'io=open('http://www.example.org/')#=>#body=io.read[0,50]#=>"["200","OK"]io.base_ur
如何在Ruby中获取BasicObject实例的类名?例如,假设我有这个:classMyObjectSystem我怎样才能使这段代码成功?编辑:我发现Object的实例方法class被定义为returnrb_class_real(CLASS_OF(obj));。有什么方法可以从Ruby中使用它? 最佳答案 我花了一些时间研究irb并想出了这个:classBasicObjectdefclassklass=class这将为任何从BasicObject继承的对象提供一个#class您可以调用的方法。编辑评论中要求的进一步解释:假设你有对象