Scripting in Drag

Discussion in 'Java' started by DanWeaver, Feb 13, 2007.

  1. DanWeaver

    DanWeaver Guest

    Can anyone help me solve this? I am trying to modify the below script
    which allows elements of class="drag" to be dragged around the screen
    by a user. I need to get (either as a hidden text box or a variable to
    be used in other functions (including vbscript
    functions) the coordinates of a dragged object after the drag
    operation ie to know exactly where each draggable element is at all
    times.

    Any help massively appreciated. Dan.

    <style type="text/css">
    .drag{
    position:relative;
    cursor:hand;
    z-index: 100;
    }
    </style>
    <script type="text/javascript">
    /***********************************************
    * Drag and Drop Script: © Dynamic Drive (http://
    www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit http://www.dynamicdrive.com/ for this script and 100s
    more.
    ***********************************************/
    var dragobject={
    z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj :
    null, dragapproved : 0,
    initialize:function(){
    document.onmousedown=this.drag
    document.onmouseup=function(){this.dragapproved=0}
    },
    drag:function(e){
    var evtobj=window.event? window.event : e
    this.targetobj=window.event? event.srcElement : e.target
    if (this.targetobj.className=="drag"){
    this.dragapproved=1
    if (isNaN(parseInt(this.targetobj.style.left)))
    {this.targetobj.style.left=0}
    if (isNaN(parseInt(this.targetobj.style.top)))
    {this.targetobj.style.top=0}
    this.offsetx=parseInt(this.targetobj.style.left)
    this.offsety=parseInt(this.targetobj.style.top)
    this.x=evtobj.clientX
    this.y=evtobj.clientY

    if (evtobj.preventDefault)
    evtobj.preventDefault()
    document.onmousemove=dragobject.moveit
    }
    },
    moveit:function(e){
    var evtobj=window.event? window.event : e
    if (this.dragapproved==1){
    this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x
    +"px"
    this.targetobj.style.top=this.offsety+evtobj.clientY-this.y
    +"px"
    return false
    }
    }
    }

    dragobject.initialize()
    </script>
     
    DanWeaver, Feb 13, 2007
    #1
    1. Advertising

  2. On Feb 14, 4:59 am, "DanWeaver" <> wrote:
    > Can anyone help me solve this?


    Given this basically comes down to..


    > <script type="text/javascript">


    ...javascript (which is not the topic of discussion
    on this forum, I have to say "you are in the
    wrong place".

    Perhaps the other post to..
    microsoft.public.scripting.jscript
    ...will yield results, though I doubt
    the ability of MS (or anyone answering
    on the MS Forums) to provide a cross-
    browser script, so I would recommend
    the *best* group for JavaScript is..
    comp.lang.javascript
    ...but be warned they do not take kindly to..

    > * Drag and Drop Script: © Dynamic Drive


    ...scripts from 'Dynamic Drive', since
    they are generally crap.

    Andrew T.
     
    Andrew Thompson, Feb 13, 2007
    #2
    1. Advertising

  3. DanWeaver <> wrote:

    [OT advice follows.]

    > Can anyone help me solve this? I am trying to modify the below script
    > which allows elements of class="drag" to be dragged around the screen
    > by a user.


    > * This notice MUST stay intact for legal use


    Rather than tying yourself to script that a) is sub-optimal, and b)
    carries advertising for other crappy script in its license, I suggest
    purchasing the O'Reilly JavaScript book and beginning from the
    drag-and-drop example in the book.

    --
    C. Benson Manica | I *should* know what I'm talking about - if I
    cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Feb 13, 2007
    #3
  4. DanWeaver

    DanWeaver Guest

    On Feb 13, 4:42 pm, Christopher Benson-Manica
    <> wrote:
    > DanWeaver <> wrote:
    >
    > [OT advice follows.]
    >
    > > Can anyone help me solve this? I am trying to modify the below script
    > > which allows elements of class="drag" to be dragged around the screen
    > > by a user.
    > > * This notice MUST stay intact for legal use

    >
    > Rather than tying yourself to script that a) is sub-optimal, and b)
    > carries advertising for other crappy script in its license, I suggest
    > purchasing the O'Reilly JavaScript book and beginning from the
    > drag-and-drop example in the book.
    >
    > --
    > C. Benson Manica | I *should* know what I'm talking about - if I
    > cbmanica(at)gmail.com | don't, I need to know. Flames welcome.



    Hi Andrew and Chris,

    Thanks for your replies- sorry about java/ javascript confusion- I
    supposed that jave people might well be experts in javescript too- but
    I am pretty inexperienced in all of this and pointers to books and
    "the way things work" on techie newsgroups are much appreciated,
    thanks for your time.

    Dan
    ps- the javascript group have not reponded- but at least I have a
    working hypoth for why now! D
     
    DanWeaver, Feb 14, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wolf
    Replies:
    0
    Views:
    575
  2. Arvind Ghai

    Drag n drop from managed to unmanaged apps

    Arvind Ghai, Feb 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    617
    Arvind Ghai
    Feb 15, 2005
  3. alex9128
    Replies:
    1
    Views:
    625
  4. Ron Stephens
    Replies:
    23
    Views:
    3,025
    Ron Stephens
    Apr 12, 2004
  5. DaveInSidney
    Replies:
    0
    Views:
    461
    DaveInSidney
    May 9, 2005
Loading...

Share This Page