score:0
You just need to properly set combination of stroke-dasharray
and stroke-dashoffset
. One option is to set the stroke-dasharray
as one "long" line and one "long" space, set stroke-dashoffset
such that the line is intially only the space and update the value of stroke-dashoffset
to show the relevant part of the path:
<!DOCTYPE html>
<html>
<body>
<svg width="300" height="300">
<path id="path0" d="M 50 50 H 250 L 50 250 H 250" stroke-width="5" stroke="black" fill="none" stroke-dasharray="1000 1000" stroke-dashoffset="1000"/>
</svg>
<script>
var p = document.getElementById("path0")
var i = 1000
setInterval(function(){ p.setAttribute("stroke-dashoffset",i--) },10)
</script>
</body>
</html>
score:0
I realized from @ccprog's comment my path had multiple "M" commands, which would explain why there is no "continuous" animation. I realized this must be done because an object orbiting Earth goes around the sphere, but SVG's are not able to convey this--hence the multiple "M" commands.
What I ended up doing is taking the generated path attribute and breaking it up into sub-paths and adding an animation-delay.
Source: stackoverflow.com
Related Query
- SVG path animation starting at multiple places
- Split an SVG path lengthwise into multiple colours
- D3 Multiple SVG Objects Following Path
- Multiple animation along path with D3
- Unclosed SVG path appears to be closed
- Recording and saving an SVG animation as an animated GIF
- Calculate SVG Path Centroid with D3.js
- Convert SVG Path d attribute to a array of points
- How to select a d3 svg path with a particular ID
- internet explorer 10 not showing svg path (d3.js graph)
- How to update an svg path with d3.js
- Find intersection of SVG path
- Pass null values to SVG path (using d3.js) to suppress missing data
- Appending multiple svg text with d3
- Modifying SVG path opacity and it's marker
- mouseout/mouseleave gets fired when mouse moves INSIDE the svg path element
- How to fill inner area between multiple SVG paths?
- SVG marker-mid on specific point on path
- Changing speed of D3 path animation
- Add region around SVG path for mouseover
- How can I set the each line color or width in SVG path
- Multiple Classes in SVG
- How can I animate infinite marker movement down an SVG path without very high CPU usage?
- Trying to add ID to svg path from json file
- Simplifying D3js' SVG path generated string
- Accessing SVG path length in d3
- How to remove shapes from filled SVG path
- D3 SVG positioning arrowhead on path
- How do I rotate or scale (transform) an SVG path relative to its center point?
- d3 draggable svg path line segment
More Query from same tag
- two dimensions brush in d3 v4
- NVD3 JavaScript charting - lineChart with duplicate right hand y-axis using 1 or more series
- How to modify the shading of an arc in d3.js?
- D3 click coordinates after pan and zoom
- Passing django url with tag to d3 js
- D3 multiline plot x axis returns NaN
- How to keep mouse over object when using drag and snap to with d3.js
- JavaScript, Web API import with D3 (Data Driven Document)
- d3.js scaleBand()'s ticks coming out of place
- How to position image on mouseover d3.js
- Mapping a string to a specific color everytime?
- How to set a CSS hover to a SVG map
- How to fix unwanted circle on / break down of SVG path element for Sankey links with d3?
- Disabling all D3 animations (for testing)
- Adding second click event listener within a click event listener
- How to show circles (created using JSON data) in reverse order using a delay function?
- D3.js: Force-directed graph, edge length proportional to edge weight
- D3 forced layout zoom and pan not working
- How to plot circles on path using React D3 for tooltip for large dataset fast
- Reverse Axis in rCharts Without Sacrificing Animation?
- d3 grouped bar chart highlight group on mouseover
- d3.js map shows empty
- Javascript D3 Histogram: thresholds producing wrong number of bins
- D3 How to style keys using their nested values
- d3: Adding links to nodes in hierarchical edge bundling
- Given an object where the value is an array, what is the most efficient way to return the pair [key, array.length]?
- How to use the quantize function with my json data file
- D3 - To add Data Labels to a simple bar chart
- How to save d3 graph as image on local machine?
- math to svg coordinate translation in javascript