Menu

Building a Drag-and-Drop Football Lineup Builder with SVG and Vanilla JavaScript
📰

Building a Drag-and-Drop Football Lineup Builder with SVG and Vanilla JavaScript

DEV Community: frontend·This is Football 247·2 days ago
#D9MP4pIH
#devtofrontend#devto#dev#shirt#const
Reading 0:00
15s threshold

Every football fan has picked an all-time XI in their head. Plenty of Sunday league managers still write their team sheet on the back of an envelope. I wanted a tool for both: pick a formation, drag players around a pitch, then download the lineup as an image or print it for the dressing room.

I built it as a free football formation creator that runs entirely in the browser: no framework, no backend, no sign-up. It's a single WordPress shortcode that outputs HTML, CSS and plain JavaScript. Here are the parts that were more interesting than I expected.

Turning "4-2-3-1" into positions on a pitch

Every formation is just a string. Split it on the dashes and you get the rows, from defence to attack:

const rows = f => f . split ( '-' ) . map ( Number ) ; // "4-2-3-1" -> [4, 2, 3, 1]

Enter fullscreen mode

Exit fullscreen mode

The goalkeeper always sits at the bottom.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.