SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I can't get this "drag and drop" script to work in Netscape 6.0.....

    Hi guys,

    I've got this GREAT, SIMPLE drag & drop layer script that works perfect in IE, but doesn't work right in Netscape and I have had no luck in fixing it so that it works right in NS6.

    Here is the code:

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    script language="JavaScript">

    var 
    dragselect=false;
    var 
    disX=0;
    var 
    disY=0;
    var 
    x=0;
    var 
    y=0;

    function 
    captureMouseMove() {
      if (
    document.all) {
        
    x=event.x;
        
    y=event.y;
      } else if (
    document.layers) {

        
    x=e.pageX;
        
    y=e.pageY;    
      }
      var 
    obj=document.getElementById("dragObject");

      if (
    dragselect) {
        
    obj.style.left=x-disX;
        
    obj.style.top=y-disY;
      }
    }

    function 
    captureMouseDown() {
      var 
    obj=document.getElementById("dragObject");
      
    disX=x-obj.offsetLeft;
      
    disY=y-obj.offsetTop;
      
    dragselect=true;
    }

    </script>


    <style type="text/CSS">

    .drag {
        position:absolute;
        left:60;
        top:40;
        width:200;
        height:75;
        background-color:yellow;
        border-style:solid;
        border-width:1px;
        border-color:black;
        padding:2px;
        cursor:hand;
    }

    </style>
    <BODY onmousemove="captureMouseMove();">

    <div id="dragObject" class="drag" onmousedown="captureMouseDown();" onmouseup="dragselect=false;">
      Drag me!
    </div>

    </BODY>

    </html> 
    Any ideas on getting my "drag n' drop" script to work correctly in Netscape 6??

    Thanks--

    GregC

  2. #2
    will code HTML for food Michel V's Avatar
    Join Date
    Sep 2000
    Location
    Corsica
    Posts
    552
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the faulty code:
    Code:
    function captureMouseMove() {
      if (document.all) {
        x=event.x;
        y=event.y;
      } else if (document.layers) {
    This is basically saying "if it's IE do this, else if it's NS4 do this". No mention of getElementById to find what to do in NS6 ! Lousy browser sniffing
    So just add an 'else if' statement for document.getElemendById and the script should work.
    [blogger: zengun] [blogware contributor: wordpress]

  3. #3
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Shin Ma
    Here's the faulty code:
    Code:
    function captureMouseMove() {
      if (document.all) {
        x=event.x;
        y=event.y;
      } else if (document.layers) {
    This is basically saying "if it's IE do this, else if it's NS4 do this". No mention of getElementById to find what to do in NS6 ! Lousy browser sniffing
    So just add an 'else if' statement for document.getElemendById and the script should work.
    Did you actually get it working yourself in Netscape?

    Because I did this w/ the NS browser check:
    PHP Code:
    else if (navigator.appName.indexOf("Netscape")) 
    {
     
    x=event.pageX;
     
    y=event.pageY;


    And it still works the same as "document.layers". I have tried document.getElementById before but when I use that to detect NS it doesn't move at all.

    With the way the script is now, it barely moves in Netscape when you try to drag it. But it moves nonetheless.

    I'm still not sure what the problem is....

    Thanks--

    GC


Bookmarks

Posting Permissions

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