簡體   English   中英

d3過渡SVG多邊形動畫在Firefox中不流暢

[英]d3 transition SVG polygon animation not smooth in Firefox

我正在使用d3為SVG多邊形設置動畫,如下所示...

https://jsfiddle.net/p6jy5t0n/35/

在Chrome / Safari上運行起來很流暢,但在Firefox上運行起來卻非常糟糕-這位明星似乎甚至在位置變化方面跳來跳去。

有問題的代碼僅依靠鏈接d3的過渡來使恆星生長,然后通過增加其筆划寬度將其收縮回正常值...

d3.select(".svgStar").transition().duration(500).ease("easeElastic")
  .each("end",function(){
    d3.select(this).transition().duration(500).ease("easeElastic")
      .style("stroke-width","0.1px")
      .style("fill",starCol);
  })
  .style("stroke-width","2.5px")
  .style("fill","#fff400");

有什么想法可以做得更好,以便在Firefox中順利過渡?

您是否嘗試過D3v5。 與D3v3相比,easyElastic在Chrome中的行為有所不同。

您知道easyElastic對過渡有什么作用嗎?

嘗試使用d3.easeLinear進行比較。

 function transformStar(){ var starCol = d3.select(".svgStar").style("fill"); var starAnimationDuration = 500; d3.select(".svgStar").style("stroke","rgb(255, 218, 93)"); d3.select(".svgStar") .transition().duration(starAnimationDuration).ease(d3.easeElastic) .style("stroke-width","2.5px") .style("fill","#fff400") .transition().duration(starAnimationDuration).ease(d3.easeElastic) .style("stroke-width","0.1px") .style("fill",starCol); } 
 <script src="https://d3js.org/d3.v5.min.js" charset="utf-8"></script> <div id="container"> <svg> <g id="starG" style="transform:translateX(50px)"> <polygon class="svgStar" fill="#ffda5d" stroke="none" w="9" cursor="default" points="94,20 101,43 125,43 106,58 113,80 94,66 74,80 80,58 62,43 86,43" style="transform: translate(-94px, 18px);"> </polygon> <text x="0" y="74" id="starTxt" style="cursor: default; font-size: 12px; font-weight: bold; text-anchor: middle; fill: rgb(20, 171, 20); stroke-width: 0px;"> Go! </text> </g> </svg> </div> <button onclick="transformStar();"> Transform Star! </button> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM