Home Ask Login Register

Developers Planet

Your answer is one click away!

Vasily Kushakov February 2016

Dragging inline SVG with JqueryUI

I'm trying to get inline SVG elements to be draggable using JQuery UI, so that I can make custom video controls.

Unfortunately I've had little luck. I've tried this SO answer in my code but haven't gotten anywhere. I've also managed to get an SVG image dragging but not inline. Is it just that JQuery UI doesn't play well with inline SVG?

Any suggested alternatives?

$(document).ready(function() {
          var v = document.querySelector("#vid");
          var b = document.querySelector("#progress");
          var x = document.querySelector("#draw_here");

          var vidTimer;
          var s;

          //wait for video and tracks to load
          var myVideoPlayer = document.getElementById('vid');
          myVideoPlayer.addEventListener('loadedmetadata', function() {

              .bind('mousedown', function(event, ui) {
              .bind('drag', function(event, ui) {
                event.target.setAttribute('x', ui.position.left);

            //  axis: "x",
            //  containment: 'parent'

            var videoControls = document.getElementById('videoControls'),
              play = document.getElementById('play'),
              playProgressInterval = false,
              progressContainer = document.getElementById("progress"),
              playProgressBar = document.getElementById("play_ball");

            // Get rid of the default controls



seahorsepip February 2016

I'll debug it and see if I can solve the problem. First thing I noticed is that you didn't close your html tag ;)

Also why "document.querySelector" when you use jquery...


You seem to use a lot non jquery code, cleaning up your code currently and I'll fix the slider.


You have forgotten that you also need to update the video progress after sliding with the slider, I'm adding code for that too.


Here's some working code: https://jsfiddle.net/seahorsepip/gLudkdd9/5/

It's still messy and working buggy, the things you did with 4% and 94% don't make any sense either.

You actually don't even need jquery ui just to make it draggable, it's pretty easy to write it with mousedown mousemove and mouseup instead.


Post Status

Asked in February 2016
Viewed 2,828 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved