{"id":55538,"date":"2022-04-29T03:01:34","date_gmt":"2022-04-28T17:01:34","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=55538"},"modified":"2022-04-29T15:42:54","modified_gmt":"2022-04-29T05:42:54","slug":"drag-and-drop-iframe-mobile-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/drag-and-drop-iframe-mobile-tutorial\/","title":{"rendered":"Drag and Drop Iframe Mobile Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/drag_around.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Drag and Drop Iframe Mobile Tutorial\"  src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/drag_around_ipad.jpg\" title=\"Drag and Drop Iframe Mobile Tutorial\" \/><\/a><p class=\"wp-caption-text\">Drag and Drop Iframe Mobile Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Drag and Drop Iframe Primer Tutorial' href='#ddipt'>Drag and Drop Iframe Primer Tutorial<\/a>&#8216;s &#8220;Drag Around&#8221; <font size=1>(HTML iframe element(s))<\/font> web application based itself on <a target=_blank href='https:\/\/www.w3schools.com\/' title='W3Schools'>W3Schools<\/a>&#8216;s <a target=_blank href='https:\/\/www.w3schools.com\/howto\/howto_js_draggable.asp' title='How To Create a Draggable HTML Element' title='Thanks to W3Schools'>How To Create a Draggable HTML Element<\/a> non-mobile drag and drop logic.  But, can we amend that logic for touch mobile platform gestures?<\/p>\n<blockquote><p>\nWell, sometimes.   It depends on the complexity of the webpage element structure and content.\n<\/p><\/blockquote>\n<p>Luckily, our &#8220;proof of concept&#8221; scenario is so pared down we can swing it via &#8230;<\/p>\n<table>\n<tr>\n<th>Non-mobile<br \/> mouse event<\/th>\n<th> &#8230; mapped to (with code tweaks) &#8230;<\/th>\n<th>Mobile<br \/> touch event<\/th>\n<\/tr>\n<tbody style=font-size:10px;>\n<tr>\n<td>onmousedown<\/td>\n<td><\/td>\n<td>ontouchstart<\/td>\n<\/tr>\n<tr>\n<td>onmousemove<\/td>\n<td><\/td>\n<td>ontouchmove<\/td>\n<\/tr>\n<tr>\n<td>onmouseup<\/td>\n<td><\/td>\n<td>ontouchend<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Yes, I hear you ask?<\/p>\n<blockquote><p>\nWhy isn&#8217;t the &#8220;mapping&#8221; for &#8220;onmousedown&#8221; end up as &#8220;ontouchdown&#8221;?\n<\/p><\/blockquote>\n<p>Well, it&#8217;s that to help out &#8220;ontouchmove&#8221; <font size=1>(after all, the most crucial event for &#8220;drag and drop&#8221; thoughts)<\/font> we hook into a &#8220;moving gesture&#8221; rather than a &#8220;discrete click gesture&#8221; we&#8217;re thinking.<\/p>\n<p>And so, below, <font color=blue>we highlight<\/font> the &#8220;mobile mappings&#8221; in the Javascript we needed to do &#8230;<\/p>\n<p><code><br \/>\n&lt;script type='text\/javascript'&gt;<br \/>\nvar goh='';<br \/>\nvar css='';<br \/>\nvar laste=null;<br \/>\nvar sofar=',';<br \/>\n<br \/>\nfunction dragit() {<br \/>\n  var sx='', isx=1;<br \/>\n  var ksx=isx;<br \/>\n  var rects=null;<br \/>\n<br \/> <br \/>\n  if (laste) {<br \/>\n<br \/>\n  isx=1;<br \/>\n  for (var jsx=1; jsx&lt;=ksx; jsx++) {<br \/>\n    \/\/if (document.getElementById(\"mydiv\" + sx + \"header\")) {<br \/>\n    \/\/  document.getElementById(\"mydiv\" + sx + \"header\").style.position='absolute';<br \/>\n    \/\/}<br \/>\n    if (document.getElementById(\"mydiv\" + sx) && sofar.indexOf(',if' + sx + ',') == -1) {<br \/>\n      \/\/alert(sx);<br \/>\n      dragElement(document.getElementById(\"mydiv\" + sx));<br \/>\n    }<br \/>\n    isx++;<br \/>\n    sx='' + isx;<br \/>\n  }<br \/>\n<br \/>\n  } else {<br \/>\n  \/\/ Make the DIV(s) element draggable:<br \/>\n  ksx=4;<br \/>\n  sx='4';<br \/>\n  while (!document.getElementById(\"mydiv\" + sx)) { ksx--; sx=('' + ksx).replace(\/^1$\/g,''); }<br \/>\n  isx=ksx;<br \/>\n  while (document.getElementById(\"mydiv\" + sx)) {<br \/>\n    if (document.getElementById(\"mydiv\" + sx + \"header\")) {<br \/>\n      rects=document.getElementById(\"mydiv\" + sx + \"header\").getBoundingClientRect();<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.position='absolute';<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.top='' + rects.top + 'px';<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.left='' + rects.left + 'px';<br \/>\n    }<br \/>\n    dragElement(document.getElementById(\"mydiv\" + sx));<br \/>\n    isx--;<br \/>\n    sx=('' + isx).replace(\/^1$\/g,'');<br \/>\n  }<br \/>\n  isx=ksx;<br \/>\n  \/\/alert(isx);<br \/>\n  if (1 == 3) {<br \/>\n  if (isx == 2) {<br \/>\n    document.getElementById(\"mydiv\" + \"header\").style.height='100vh';<br \/>\n  } else if (isx == 3) {<br \/>\n    document.getElementById(\"mydiv\" + \"header\").style.height='40vh';<br \/>\n    document.getElementById(\"mydiv2\" + \"header\").style.height='40vh';<br \/>\n    \/\/document.getElementById(\"if\" + \"\").style.height='100%';<br \/>\n    \/\/document.getElementById(\"if2\" + \"\").style.height='100%';<br \/>\n  } else {<br \/>\n    document.getElementById(\"mydiv\" + \"header\").style.height='30vh';<br \/>\n    document.getElementById(\"mydiv2\" + \"header\").style.height='30vh';<br \/>\n    document.getElementById(\"mydiv3\" + \"header\").style.height='30vh';<br \/>\n    \/\/document.getElementById(\"if\" + \"\").style.height='100%';<br \/>\n    \/\/document.getElementById(\"if2\" + \"\").style.height='100%';<br \/>\n    \/\/document.getElementById(\"if3\" + \"\").style.height='100%';<br \/>\n  }<br \/>\n  }<br \/>\n<br \/> <br \/>\n  sx='';<br \/>\n  ksx=isx;<br \/>\n  isx=1;<br \/>\n  for (var jsx=1; jsx&lt;=ksx; jsx++) {<br \/>\n    \/\/if (document.getElementById(\"mydiv\" + sx + \"header\")) {<br \/>\n    \/\/  document.getElementById(\"mydiv\" + sx + \"header\").style.position='absolute';<br \/>\n    \/\/}<br \/>\n    \/\/if (document.getElementById(\"mydiv\" + sx)) {<br \/>\n    \/\/  dragElement(document.getElementById(\"mydiv\" + sx));<br \/>\n    \/\/}<br \/>\n    if (document.getElementById(\"mydiv\" + sx + \"header\") && !document.getElementById(\"if\" + sx)) {<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.visibility='hidden';<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.display='none';<br \/>\n    }<br \/>\n    isx++;<br \/>\n    sx='' + isx;<br \/>\n    if (document.getElementById(\"mydiv\" + sx + \"header\") && !document.getElementById(\"if\" + sx)) {<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.visibility='hidden';<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.display='none';<br \/>\n    }<br \/>\n  }<br \/>\n  }<br \/>\n<br \/> <br \/>\n}<br \/>\n<br \/>\nfunction dragElement(elmnt) {<br \/>\n  var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;<br \/>\n  if (document.getElementById(elmnt.id + \"header\")) {<br \/>\n    \/\/ if present, the header is where you move the DIV from:<br \/>\n    <font color=blue>if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n    console.log('ontouchdown');<br \/>\n    document.getElementById(elmnt.id + \"header\").ontouchstart = dragMouseDown;<br \/>\n    document.getElementById(elmnt.id + \"header\").style.textDecoration = 'underline';<br \/>\n    } else {<\/font><br \/>\n    document.getElementById(elmnt.id + \"header\").onmousedown = dragMouseDown;<br \/>\n    <font color=blue>}<\/font><br \/>\n  } else {<br \/>\n    \/\/ otherwise, move the DIV from anywhere inside the DIV:<br \/>\n    <font color=blue>if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n    console.log('Ontouchdown');<br \/>\n    elmnt.ontouchstart = dragMouseDown;<br \/>\n    elmnt.style.textDecoration = 'underline';<br \/>\n    } else {<\/font><br \/>\n    elmnt.onmousedown = dragMouseDown;<br \/>\n    <font color=blue>}<\/font><br \/>\n  }<br \/>\n<br \/>\n  function dragMouseDown(e) {<br \/>\n    e = e || window.event;<br \/>\n    e.preventDefault();<br \/>\n    \/\/ get the mouse cursor position at startup:<br \/>\n    <font color=blue>\/\/<\/font>pos3 = e.clientX;<br \/>\n    <font color=blue>\/\/<\/font>pos4 = e.clientY;<br \/>\n<br \/>\n       <font color=blue>if (e.touches) {<br \/>\n       if (e.touches[0].pageX) {<br \/>\n       pos3 = e.touches[0].pageX;<br \/>\n       pos4 = e.touches[0].pageY;<br \/>\n       } else {<br \/>\n       pos3 = e.touches[0].clientX;<br \/>\n       pos4 = e.touches[0].clientY;<br \/>\n       }<br \/>\n       console.log('pos3=' + pos3 + ',pos4=' + pos4);<br \/>\n       } else if (e.clientX || e.clientY) {<\/font><br \/>\n        pos3 = e.clientX;<br \/>\n        pos4 = e.clientY;<br \/>\n       <font color=blue>} else {<br \/>\n        pos3 = e.pageX;<br \/>\n        pos4 = e.pageY;<br \/>\n       }<\/font><br \/>\n<br \/>\n    laste=e.target;<br \/>\n    <font color=blue>if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n    document.ontouchend = closeDragElement;<br \/>\n    } else {<\/font><br \/>\n    document.onmouseup = closeDragElement;<br \/>\n    <font color=blue>}<\/font><br \/>\n    \/\/ call a function whenever the cursor moves:<br \/>\n    <font color=blue>if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n    document.ontouchmove = elementDrag;<br \/>\n    } else {<\/font><br \/>\n    document.onmousemove = elementDrag;<br \/>\n    <font color=blue>}<\/font><br \/>\n  }<br \/>\n<br \/>\n  function elementDrag(e) {<br \/>\n    e = e || window.event;<br \/>\n    e.preventDefault();<br \/>\n    \/\/ calculate the new cursor position:<br \/>\n<br \/> <br \/>\n       <font color=blue>if (e.touches) {<br \/>\n       if (e.touches[0].pageX) {<br \/>\n<br \/>\n    pos1 = pos3 - e.touches[0].pageX;<br \/>\n    pos2 = pos4 - e.touches[0].pageY;<br \/>\n    pos3 = e.touches[0].pageX;<br \/>\n    pos4 = e.touches[0].pageY;<br \/>\n<br \/>\n       } else {<br \/>\n<br \/>\n    pos1 = pos3 - e.touches[0].clientX;<br \/>\n    pos2 = pos4 - e.touches[0].clientY;<br \/>\n    pos3 = e.touches[0].clientX;<br \/>\n    pos4 = e.touches[0].clientY;<br \/>\n<br \/>\n       }<br \/>\n       console.log('pos1=' + pos1 + ',pos2=' + pos2);<br \/>\n       } else if (e.clientX || e.clientY) {<\/font><br \/>\n    pos1 = pos3 - e.clientX;<br \/>\n    pos2 = pos4 - e.clientY;<br \/>\n    pos3 = e.clientX;<br \/>\n    pos4 = e.clientY;<br \/>\n       <font color=blue>} else {<br \/>\n    pos1 = pos3 - e.pageX;<br \/>\n    pos2 = pos4 - e.pageY;<br \/>\n    pos3 = e.pageX;<br \/>\n    pos4 = e.pageY;<br \/>\n       }<\/font><br \/>\n<br \/> <br \/>\n    <font color=blue>\/\/<\/font>pos1 = pos3 - e.clientX;<br \/>\n    <font color=blue>\/\/<\/font>pos2 = pos4 - e.clientY;<br \/>\n    <font color=blue>\/\/<\/font>pos3 = e.clientX;<br \/>\n    <font color=blue>\/\/<\/font>pos4 = e.clientY;<br \/>\n    \/\/ set the element's new position:<br \/>\n    elmnt.style.top = (elmnt.offsetTop - pos2) + \"px\";<br \/>\n    elmnt.style.left = (elmnt.offsetLeft - pos1) + \"px\";<br \/>\n    goh=elmnt.outerHTML;<br \/>\n    if (css == '') {<br \/>\n      css=\"?css\" + e.target.id.replace('mydiv','').replace('header','').replace('if','') + \"=\" + encodeURIComponent('top:' + elmnt.style.top + ';left:' + elmnt.style.left + ';');<br \/>\n    } else {<br \/>\n      if (css.indexOf('css' + e.target.id.replace('mydiv','').replace('header','') + '=') != -1) {<br \/>\n        css=css.replace(css.split('css' + e.target.id.replace('mydiv','').replace('header','').replace('if','') + '=')[1].split('&')[0], encodeURIComponent('top:' + elmnt.style.top + ';left:' + elmnt.style.left + ';'));<br \/>\n      } else {<br \/>\n        css+=\"&css\" + e.target.id.replace('mydiv','').replace('header','').replace('if','') + \"=\" + encodeURIComponent('top:' + elmnt.style.top + ';left:' + elmnt.style.left + ';');<br \/>\n      }<br \/>\n    }<br \/>\n    console.log(goh);<br \/>\n  }<br \/>\n<br \/>\n  function closeDragElement() {<br \/>\n    \/\/ stop moving when mouse button is released:<br \/>\n    sofar+=laste.id + ',';<br \/>\n    <font color=blue>if (navigator.userAgent.match(\/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile\/i)) {<br \/>\n    document.ontouchmove = null;<br \/>\n    } else {<\/font><br \/>\n    document.onmouseup = null;<br \/>\n    document.onmousemove = null;<br \/>\n    <font color=blue>}<\/font><br \/>\n    \/\/alert(goh);<br \/>\n    \/\/dragit();<br \/>\n    goh='';<br \/>\n    if (css != '') {<br \/>\n      \/\/document.getElementById('myh1').innerHTML+=' ' + decodeURIComponent(css);<br \/>\n      setTimeout(st, 3000);<br \/>\n    }<br \/>\n  }<br \/>\n}<br \/>\n<br \/> <br \/>\n  function st() {<br \/>\n      if ((location.search.split('css=')[1] ? decodeURIComponent(location.search.split('css=')[1].split('&')[0]) : '') != '' && css.indexOf('css=') == -1) {<br \/>\n       css+='&css=' + encodeURIComponent((location.search.split('css=')[1] ? decodeURIComponent(location.search.split('css=')[1].split('&')[0]) : ''));<br \/>\n      }<br \/>\n      if ((location.search.split('css2=')[1] ? decodeURIComponent(location.search.split('css2=')[1].split('&')[0]) : '') != '' && css.indexOf('css2=') == -1) {<br \/>\n       css+='&css2=' + encodeURIComponent((location.search.split('css2=')[1] ? decodeURIComponent(location.search.split('css2=')[1].split('&')[0]) : ''));<br \/>\n      }<br \/>\n      if ((location.search.split('css3=')[1] ? decodeURIComponent(location.search.split('css3=')[1].split('&')[0]) : '') != '' && css.indexOf('css3=') == -1) {<br \/>\n       css+='&css3=' + encodeURIComponent((location.search.split('css3=')[1] ? decodeURIComponent(location.search.split('css3=')[1].split('&')[0]) : ''));<br \/>\n      }<br \/>\n      \/\/location.href=document.URL.split('#')[0].split('?')[0] + css + '&numsel=' + document.getElementById('numsel').value;<br \/>\n  }<br \/>\n&lt;\/script&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/drag_around.html-GETME\" title=\"drag_around.html\">your changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/drag_around.html\" title=\"Click picture\">&#8220;Drag Around&#8221; (up to 3) HTML Iframe Element(s)<\/a>.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/drag-and-drop-iframe-mobile-tutorial\/'>Drag and Drop Iframe Mobile Tutorial<\/a>.<\/p-->\n<hr>\n<p id='ddipt'>Previous relevant <a target=_blank title='Drag and Drop Iframe Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/drag-and-drop-iframe-primer-tutorial\/'>Drag and Drop Iframe Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/drag_around.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Drag and Drop Iframe Primer Tutorial\"  src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/drag_around.jpg\" title=\"Drag and Drop Iframe Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">Drag and Drop Iframe Primer Tutorial<\/p><\/div>\n<p>We were &#8220;really taken&#8221; by the possibilities trying out <a target=_blank href='https:\/\/www.w3schools.com\/howto\/howto_js_draggable.asp' title='How To Create a Draggable HTML Element' title='Thanks to W3Schools'>How To Create a Draggable HTML Element<\/a> (by <a target=_blank href='https:\/\/www.w3schools.com\/' title='W3Schools'>W3Schools<\/a>), to drag and drop elements on non-mobile webpages.  So much so, we wrote a &#8220;proof of concept&#8221; dragger and dropper of up to three iframe elements in the one webpage.<\/p>\n<p>The Javascript &#8230;<\/p>\n<p><code><br \/>\n&lt;script type='text\/javascript'&gt;<br \/>\nvar goh='';<br \/>\nvar css='';<br \/>\nvar laste=null;<br \/>\nvar sofar=',';<br \/>\n<br \/>\nfunction dragit() {<br \/>\n  var sx='', isx=1;<br \/>\n  var ksx=isx;<br \/>\n  var rects=null;<br \/>\n<br \/> <br \/>\n  if (laste) {<br \/>\n<br \/>\n  isx=1;<br \/>\n  for (var jsx=1; jsx&lt;=ksx; jsx++) {<br \/>\n    \/\/if (document.getElementById(\"mydiv\" + sx + \"header\")) {<br \/>\n    \/\/  document.getElementById(\"mydiv\" + sx + \"header\").style.position='absolute';<br \/>\n    \/\/}<br \/>\n    if (document.getElementById(\"mydiv\" + sx) && sofar.indexOf(',if' + sx + ',') == -1) {<br \/>\n      \/\/alert(sx);<br \/>\n      dragElement(document.getElementById(\"mydiv\" + sx));<br \/>\n    }<br \/>\n    isx++;<br \/>\n    sx='' + isx;<br \/>\n  }<br \/>\n<br \/>\n  } else {<br \/>\n  \/\/ Make the DIV(s) element draggable:<br \/>\n  ksx=4;<br \/>\n  sx='4';<br \/>\n  while (!document.getElementById(\"mydiv\" + sx)) { ksx--; sx=('' + ksx).replace(\/^1$\/g,''); }<br \/>\n  isx=ksx;<br \/>\n  while (document.getElementById(\"mydiv\" + sx)) {<br \/>\n    if (document.getElementById(\"mydiv\" + sx + \"header\")) {<br \/>\n      rects=document.getElementById(\"mydiv\" + sx + \"header\").getBoundingClientRect();<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.position='absolute';<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.top='' + rects.top + 'px';<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.left='' + rects.left + 'px';<br \/>\n    }<br \/>\n    dragElement(document.getElementById(\"mydiv\" + sx));<br \/>\n    isx--;<br \/>\n    sx=('' + isx).replace(\/^1$\/g,'');<br \/>\n  }<br \/>\n  isx=ksx;<br \/>\n  \/\/alert(isx);<br \/>\n  if (1 == 3) {<br \/>\n  if (isx == 2) {<br \/>\n    document.getElementById(\"mydiv\" + \"header\").style.height='100vh';<br \/>\n  } else if (isx == 3) {<br \/>\n    document.getElementById(\"mydiv\" + \"header\").style.height='40vh';<br \/>\n    document.getElementById(\"mydiv2\" + \"header\").style.height='40vh';<br \/>\n    \/\/document.getElementById(\"if\" + \"\").style.height='100%';<br \/>\n    \/\/document.getElementById(\"if2\" + \"\").style.height='100%';<br \/>\n  } else {<br \/>\n    document.getElementById(\"mydiv\" + \"header\").style.height='30vh';<br \/>\n    document.getElementById(\"mydiv2\" + \"header\").style.height='30vh';<br \/>\n    document.getElementById(\"mydiv3\" + \"header\").style.height='30vh';<br \/>\n    \/\/document.getElementById(\"if\" + \"\").style.height='100%';<br \/>\n    \/\/document.getElementById(\"if2\" + \"\").style.height='100%';<br \/>\n    \/\/document.getElementById(\"if3\" + \"\").style.height='100%';<br \/>\n  }<br \/>\n  }<br \/>\n<br \/> <br \/>\n  sx='';<br \/>\n  ksx=isx;<br \/>\n  isx=1;<br \/>\n  for (var jsx=1; jsx&lt;=ksx; jsx++) {<br \/>\n    \/\/if (document.getElementById(\"mydiv\" + sx + \"header\")) {<br \/>\n    \/\/  document.getElementById(\"mydiv\" + sx + \"header\").style.position='absolute';<br \/>\n    \/\/}<br \/>\n    \/\/if (document.getElementById(\"mydiv\" + sx)) {<br \/>\n    \/\/  dragElement(document.getElementById(\"mydiv\" + sx));<br \/>\n    \/\/}<br \/>\n    if (document.getElementById(\"mydiv\" + sx + \"header\") && !document.getElementById(\"if\" + sx)) {<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.visibility='hidden';<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.display='none';<br \/>\n    }<br \/>\n    isx++;<br \/>\n    sx='' + isx;<br \/>\n    if (document.getElementById(\"mydiv\" + sx + \"header\") && !document.getElementById(\"if\" + sx)) {<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.visibility='hidden';<br \/>\n      document.getElementById(\"mydiv\" + sx + \"header\").style.display='none';<br \/>\n    }<br \/>\n  }<br \/>\n  }<br \/>\n<br \/> <br \/>\n}<br \/>\n<br \/>\nfunction dragElement(elmnt) {<br \/>\n  var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;<br \/>\n  if (document.getElementById(elmnt.id + \"header\")) {<br \/>\n    \/\/ if present, the header is where you move the DIV from:<br \/>\n    document.getElementById(elmnt.id + \"header\").onmousedown = dragMouseDown;<br \/>\n  } else {<br \/>\n    \/\/ otherwise, move the DIV from anywhere inside the DIV:<br \/>\n    elmnt.onmousedown = dragMouseDown;<br \/>\n  }<br \/>\n<br \/>\n  function dragMouseDown(e) {<br \/>\n    e = e || window.event;<br \/>\n    e.preventDefault();<br \/>\n    \/\/ get the mouse cursor position at startup:<br \/>\n    pos3 = e.clientX;<br \/>\n    pos4 = e.clientY;<br \/>\n    laste=e.target;<br \/>\n    document.onmouseup = closeDragElement;<br \/>\n    \/\/ call a function whenever the cursor moves:<br \/>\n    document.onmousemove = elementDrag;<br \/>\n  }<br \/>\n<br \/>\n  function elementDrag(e) {<br \/>\n    e = e || window.event;<br \/>\n    e.preventDefault();<br \/>\n    \/\/ calculate the new cursor position:<br \/>\n    pos1 = pos3 - e.clientX;<br \/>\n    pos2 = pos4 - e.clientY;<br \/>\n    pos3 = e.clientX;<br \/>\n    pos4 = e.clientY;<br \/>\n    \/\/ set the element's new position:<br \/>\n    elmnt.style.top = (elmnt.offsetTop - pos2) + \"px\";<br \/>\n    elmnt.style.left = (elmnt.offsetLeft - pos1) + \"px\";<br \/>\n    goh=elmnt.outerHTML;<br \/>\n    if (css == '') {<br \/>\n      css=\"?css\" + e.target.id.replace('mydiv','').replace('header','').replace('if','') + \"=\" + encodeURIComponent('top:' + elmnt.style.top + ';left:' + elmnt.style.left + ';');<br \/>\n    } else {<br \/>\n      if (css.indexOf('css' + e.target.id.replace('mydiv','').replace('header','') + '=') != -1) {<br \/>\n        css=css.replace(css.split('css' + e.target.id.replace('mydiv','').replace('header','').replace('if','') + '=')[1].split('&')[0], encodeURIComponent('top:' + elmnt.style.top + ';left:' + elmnt.style.left + ';'));<br \/>\n      } else {<br \/>\n        css+=\"&css\" + e.target.id.replace('mydiv','').replace('header','').replace('if','') + \"=\" + encodeURIComponent('top:' + elmnt.style.top + ';left:' + elmnt.style.left + ';');<br \/>\n      }<br \/>\n    }<br \/>\n    console.log(goh);<br \/>\n  }<br \/>\n<br \/>\n  function closeDragElement() {<br \/>\n    \/\/ stop moving when mouse button is released:<br \/>\n    sofar+=laste.id + ',';<br \/>\n    document.onmouseup = null;<br \/>\n    document.onmousemove = null;<br \/>\n    \/\/alert(goh);<br \/>\n    \/\/dragit();<br \/>\n    goh='';<br \/>\n    if (css != '') {<br \/>\n      \/\/document.getElementById('myh1').innerHTML+=' ' + decodeURIComponent(css);<br \/>\n      setTimeout(st, 3000);<br \/>\n    }<br \/>\n  }<br \/>\n}<br \/>\n<br \/> <br \/>\n  function st() {<br \/>\n      if ((location.search.split('css=')[1] ? decodeURIComponent(location.search.split('css=')[1].split('&')[0]) : '') != '' && css.indexOf('css=') == -1) {<br \/>\n       css+='&css=' + encodeURIComponent((location.search.split('css=')[1] ? decodeURIComponent(location.search.split('css=')[1].split('&')[0]) : ''));<br \/>\n      }<br \/>\n      if ((location.search.split('css2=')[1] ? decodeURIComponent(location.search.split('css2=')[1].split('&')[0]) : '') != '' && css.indexOf('css2=') == -1) {<br \/>\n       css+='&css2=' + encodeURIComponent((location.search.split('css2=')[1] ? decodeURIComponent(location.search.split('css2=')[1].split('&')[0]) : ''));<br \/>\n      }<br \/>\n      if ((location.search.split('css3=')[1] ? decodeURIComponent(location.search.split('css3=')[1].split('&')[0]) : '') != '' && css.indexOf('css3=') == -1) {<br \/>\n       css+='&css3=' + encodeURIComponent((location.search.split('css3=')[1] ? decodeURIComponent(location.search.split('css3=')[1].split('&')[0]) : ''));<br \/>\n      }<br \/>\n      \/\/location.href=document.URL.split('#')[0].split('?')[0] + css + '&numsel=' + document.getElementById('numsel').value;<br \/>\n  }<br \/>\n&lt;\/script&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; is interesting in the timing of when some &#8220;drag header&#8221; elements should be turned into <i>position:absolute<\/i> (with top:[&#8220;drag header&#8221; element].<a target=_blank title='Javascript DOM getBoundingClientRect information from W3schools' href='https:\/\/www.w3schools.com\/jsref\/met_element_getboundingclientrect.asp'>getBoundingClientRect<\/a>().top and left:[&#8220;drag header&#8221; element].getBoundingClientRect().left) determined in reverse order so that the initial <i>relative<\/i> position can be the guide for the establishment of reasonable <i>top<\/i> and <i>left<\/i> <i>absolute<\/i> positions.<\/p>\n<p>So feel free to try today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/drag_around.html_GETME\">proof of concept<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/drag_around.html\" title=\"Click picture\">&#8220;Drag Around&#8221; web application<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d55532' onclick='var dv=document.getElementById(\"d55532\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/drag\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55532' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d55538' onclick='var dv=document.getElementById(\"d55538\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/ipad\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55538' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday&#8217;s Drag and Drop Iframe Primer Tutorial&#8216;s &#8220;Drag Around&#8221; (HTML iframe element(s)) web application based itself on W3Schools&#8216;s How To Create a Draggable HTML Element non-mobile drag and drop logic. But, can we amend that logic for touch mobile platform &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/drag-and-drop-iframe-mobile-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,12,14,20,37],"tags":[2824,76,354,2237,364,1549,485,2208,576,587,626,630,652,3272,795,1871,2219,2723,873,876,894,1988,997,1986,2945,1292,1294,1319,1418],"class_list":["post-55538","post","type-post","status-publish","format-standard","hentry","category-android","category-elearning","category-event-driven-programming","category-ios","category-tutorials","tag-absolute","tag-android","tag-dom","tag-drag","tag-drag-and-drop","tag-element","tag-gesture","tag-getboundingclientrect","tag-html","tag-iframe","tag-ios","tag-ipad","tag-javascript","tag-left","tag-mobile","tag-move","tag-onmousemove","tag-ontouchmove","tag-ontouchstart","tag-opacity","tag-overlay","tag-position","tag-programming","tag-proof-of-concept","tag-relative","tag-top","tag-touch","tag-tutorial","tag-webpage"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55538"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=55538"}],"version-history":[{"count":7,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55538\/revisions"}],"predecessor-version":[{"id":55565,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55538\/revisions\/55565"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=55538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=55538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=55538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}