/    Sign up×
Community /Pin to ProfileBookmark

Scripting SVG

Hello,

Will someone please show me how to script a line that is built with Scalable Vector Graphics. I would like the line to draw itself to the screen. What I mean by that is:

I want an empty page to load, then the svg element would be created and the x2 and/or y2 cooridinates would increment.

For example:

<svg xmlns=”http://www.w3.org/2000/svg” version=”1.1″>

<line x1=”50″ y1=”50″ x2=”51″ y2=”50″ style=”stroke:rgb(0,0,0); stroke-width:1″ />

<svg>

With the line above, the starting point is 50px from the left and 50px from the top. The “x” axis will increment and the “y” axis will stay at 50 meaning that we’ll draw a horizontal line.

How can we script that? ?

Previously, I was drawing lines using <div> and manipulating CSS height and width. This is awkward due to diagonal lines and such. Then I started using jsDraw2d.js which was going fairly well until I started running into some performance issues. So now, I would like to experiment SVG. However, I am not sure how javascript works with svg. 😮

Will someone please bring me up to speed?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @vb2java spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...