javascript - Dragging inline SVG with JqueryUI -


i'm trying inline svg elements draggable using jquery ui, can make custom video controls.

unfortunately i've had little luck. i've tried so answer in code haven't gotten anywhere. i've managed svg image dragging not inline. jquery ui doesn't play 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 video , tracks load            var myvideoplayer = document.getelementbyid('vid');            myvideoplayer.addeventlistener('loadedmetadata', function() {                $("#play_ball").draggable()                .bind('mousedown', function(event, ui) {                  $(event.target.parentelement).append(event.target);                })                .bind('drag', function(event, ui) {                  event.target.setattribute('x', ui.position.left);                });                              //$("#play_ball").draggable({              //  axis: "x",              //  containment: 'parent'              //});                var videocontrols = document.getelementbyid('videocontrols'),                play = document.getelementbyid('play'),                playprogressinterval = false,                progresscontainer = document.getelementbyid("progress"),                playprogressbar = document.getelementbyid("play_ball");                  // rid of default controls              v.removeattribute('controls');                handlebuttonpresses();                  function handlebuttonpresses() {                // when play button clicked, playor pause video.                play.addeventlistener('click', playpause, false);                  // when play button pressed, witch "pause" symbol.                 v.addeventlistener('play', function() {                  play.title = 'pause';                  play.innerhtml = '<span id="pausebutton">&#x2590;&#x2590;</span>';                    // begin tracking video's progress.                    trackplayprogress();                }, false);                  // when pause button pressed, switch "play" symbol.                 v.addeventlistener('pause', function() {                  play.title = 'play';                  play.innerhtml = '&#x25ba;';                    // video paused, stop tracking progress.                   stoptrackingplayprogress();                }, false);                    // when video has concluded, pause it.                 v.addeventlistener('ended', function() {                  this.currenttime = 0;                  this.pause();                }, false);                    v.addeventlistener('touchstart', function(e) {                  var sdate = new date();                  stime = sdate.gettime();;                  var touchobj = e.changedtouches[0]                  console.log(touchobj.target) // returns element touch point landed on                    // var xpos =                    // var ypos =                     // console.log("position is"+e.pagex + ", " + e.pagey);                    // console.log("position is" + xpos + ", " + ypos);                  }, false);                  v.addeventlistener('touchend', function() {                  var edate = new date();                  etime = edate.gettime();;                  if (etime - stime >= 99) {                    alert("you held it!");                  }                  }, false);              }                function playpause() {                if (v.paused || v.ended) {                  if (v.ended) {                    v.currenttime = 0;                  }                  v.play();                } else {                  v.pause();                }              }                function vidupdate() {                $scope.sliderv.value = parseint(v.currenttime, 10);                $scope.$broadcast('rzsliderforcerender');              }                // every 50 milliseconds, update play progress.                function trackplayprogress() {                (function progresstrack() {                  updateplayprogress();                  vidupdate();                  // pause @ chapter breaks                  //ignore first cue                  (var = 1; < cues.length; i++) {                    if (v.currenttime >= cues[i].starttime - .10 && v.currenttime <= cues[i].starttime + .10) {                      v.currenttime += .3;                      v.pause();                      }                  }                  playprogressinterval = settimeout(progresstrack, 50);                })();              }                function updateplayprogress() {                playprogressbar.style.width = ((v.currenttime / v.duration) * (progresscontainer.offsetwidth)) + "px";                playprogressbar.setattribute("cx", (4 + ((v.currenttime / v.duration) * 94) + "%"));              }                // video stopped, stop updating progress.               function stoptrackingplayprogress() {                cleartimeout(playprogressinterval);              }                }); //ends wait vid            }); //ends doc ready
/* progress bar */    #progress {    position: absolute !important;    left: 7%;    height: 70%;    width: 90%;    cursor: pointer;    z-index: 4;  }  #progress_box {    height: 95%;    width: 100%;    border: 1px solid #292929;    -webkit-border-radius: 5px;    -moz-border-radius: 5px;    border-radius: 5px;    background: #303030;    /* old browsers */    background: -moz-linear-gradient(top, #303030 0%, #545454 49%, #545454 51%, #7e7e7e 100%);    /* ff3.6-15 */    background: -webkit-linear-gradient(top, #303030 0%, #545454 49%, #545454 51%, #7e7e7e 100%);    /* chrome10-25,safari5.1-6 */    background: linear-gradient(to bottom, #303030 0%, #545454 49%, #545454 51%, #7e7e7e 100%);    /* w3c, ie10+, ff16+, chrome26+, opera12+, safari7+ */    filter: progid: dximagetransform.microsoft.gradient(startcolorstr='#303030', endcolorstr='#7e7e7e', gradienttype=0);    /* ie6-9 */    -webkit-box-shadow: 0 1px 0 #292929, 0 -1px 0 #292929;    -moz-box-shadow: 0 1px 0 #292929, 0 -1px 0 #292929;    box-shadow: 0 1px 0 #292929, 0 -1px 0 #292929;    margin: 2px 0 0 5px;    padding: 2px;    overflow: hidden;    z-index: 4;  }  #play_progress {    display: block;    height: 40%;    width: 100%;    background-color: #fff;    background: -webkit-gradient(linear, left top, left bottom, from(#e3e3e3), color-stop(.5, white), to(#e3e3e3));    background: -moz-linear-gradient(top, #e3e3e3, white 50%, #e3e3e3);    -webkit-border-radius: 5px;    -moz-border-radius: 5px;    border-radius: 5px;    z-index: 4;  }  #play_time {    float: right;    margin: 7px 0 0 5px;    font-size: 10px;    font-weight: normal;    font-family: helvetica, arial, sans-serif;    line-height: 1;    z-index: 4;  }  #spacer {    display: block;    width: 100%;    height: 30%;  }  #slidervideo {    position: absolute;    top: 50px;    bottom: 50px;    right: 1%;  }
<!doctype html>  <html>    <head>    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.js"></script>  </head>    <body>    <div id="player">      <video id="vid" controls>        <source id="mp4" src="http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4" type="video/mp4">      </video>      <div id="videocontrols">        <button id="play" title="play">&#x25ba;</button>        <div id="progress">          <svg xmlns="http://www.w3.org/2000/svg" id="draw_here" height="100" width="100%">            <line id="play_bar" x1="5%" y1="15" x2="100%" y2="15" style="stroke:#7e7f81;stroke-width:2" />            <circle id="play_ball" cx="4%" cy="15" r="13" fill="#b0c4de" />          </svg>          <span id="spacer"></span>        </div>        <button id="instructorbtn" title="instructor">!</button>      </div>    </div>  </body>

i'll debug , see if can solve problem. first thing noticed didn't close html tag ;)

also why "document.queryselector" when use jquery...

edit:

you seem use lot non jquery code, cleaning code , i'll fix slider.

edit2:

you have forgotten need update video progress after sliding slider, i'm adding code too.

edit3:

here's working code: https://jsfiddle.net/seahorsepip/gludkdd9/5/

it's still messy , working buggy, things did 4% , 94% don't make sense either.

you don't need jquery ui make draggable, it's pretty easy write mousedown mousemove , mouseup instead.

. 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -