www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] XHTML 1.0 Strict and moving divs..

  1. #1
    Join Date
    Mar 2009
    Posts
    3

    resolved [RESOLVED] 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. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Units are necessary:
    Code:
    dobj.style.left = someValue + "px";

  3. #3
    Join Date
    Mar 2009
    Posts
    3
    Quote Originally Posted by Fang View Post
    Units are necessary:
    Code:
    dobj.style.left = someValue + "px";
    Thanks for your reply. When I first changed to the xhtml strict doctype, everything broke; mainly because I wasn't specifying 'px'. I initially thought that was the issue with this function, but when I tried altering it with code similar to what you suggest, it still didn't work. I'll give it a try again when I get back from work, maybe something else was wrong when I tried it before.

    So is the correct way to write this:
    Code:
    ty = parseInt(dobj.style.top+0 + 'px');
    or do I need to append the px to ty after the parseInt has acted?

    I must confess this bit of js goes a bit above my head, nearly all my other js I wrote myself, but this section is nabbed.. goes to show, messing with stuff you don't understand makes work in the long run.

    Anyway, many thanks for your suggestion.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    ty = parseInt(dobj.style.top+0) + 'px';

  5. #5
    Join Date
    Mar 2009
    Posts
    3
    Ok, ignore my last post, or the question bit at least. I think I know what I need to do now. Thanks again for the advice, can't believe I've spent several days trying to figure out what was going wrong..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles