Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    XHTML 1.0 Strict and moving divs..

    Hi,

    I've been making a site recently that relies mainly on javascript and has several movable divs. Until recently the doctype was html transitional, I've now changed it to XHTML 1.0 Strict and changed all the code to make it compliant, it validates fine, everything works as expected barring some dragable divs.

    This has been driving me mad for a couple of days now, if I swap the doctype back everything is fine. Am I missing something fundamental here? Is the below code just not compatible with the strict xhtml doctype? Or is there something simple I can change?

    Any help/advice much appreciated!
    (curWid = the id of the elemnt I want to move)

    Code:
    var ie = document.all;
    var nn6 = document.getElementById &&! document.all;
    
    var isdrag = false;
    var x, y;
    var dobj;
    
    function movemouse( e ) {
      if( isdrag ) {
        dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
        dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
        return false;
      }
    }
    
    function selectmouse( e ) {
      var fobj       = nn6 ? e.target : event.srcElement;
      var topelement = nn6 ? "HTML" : "BODY";
    
      while (fobj.tagName != topelement && fobj.className != "dragme") {
        fobj = nn6 ? fobj.parentNode : fobj.parentElement;
      }
    
      if (fobj.className=="dragme") {
        isdrag = true;
        dobj = document.getElementById(curWid);
        tx = parseInt(dobj.style.left+0);
        ty = parseInt(dobj.style.top+0);
        x = nn6 ? e.clientX : event.clientX;
        y = nn6 ? e.clientY : event.clientY;
        document.onmousemove=movemouse;
        return false;
      }
    }

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    (curWid = the id of the elemnt I want to move)
    How about posting a link or the complete code?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    it rather an old code. A quick debug could be:
    Code:
    dobj.style.left = nn6 ? (tx + e.pageX - x)+'px' : tx + event.clientX - x;
    dobj.style.top  = nn6 ? (ty + e.pageY - y)+'px' : ty + event.clientY - y;
    ...
    while (fobj.nodeName != topelement && fobj.className != "dragme") {
    ...
    tx = parseInt(dobj.style.left,10);
    ty = parseInt(dobj.style.top,10);
    ...
    And, if embedded, make sure your javascript is nested within CDATA islands:
    Code:
    <script type="text/javascript">
    /*<![CDATA[*/
    ... embedded code here ...
    /*]]>*/
    </script>
    But I would have coded otherwise on detecting rather the e/event and pageX/clientX. And I would have considered the documentElement rather than HTML or BODY as the upmost element...
    Last edited by Kor; 03-17-2009 at 10:50 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    dusty42 (03-17-2009)

  • #4
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Many thanks for the replies.

    The first thing I tried was adding the 'px', it appears though I was adding it in the wrong way, I appreciate your guidance on this.

    I think I understand what you mean regarding the upmost element, but I'm not sure what you mean about detecting 'e/event and pageX/clientX'. I should have really found out how to do this myself, it's questionable whether nabbing this bit of code has actually saved me any time and I still don't understand half of it. Anyway, once again many thanks for your help and I'll try and do some reading tonight on the other things you mentioned that might improve my way of doing this.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •