SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with moving layer(javascript)

    Hi,

    I have a problem with javascript in moving layer.The basic requirement is to create a moving layer,but the layer should be 100% visible on screen it will not hide when you move layer with mouse.Here I am attaching the file.

    If change the code in dd(e) function the layer is moving well,but it is moving out the screen.


    function dd(e){
    if (!ddEnabled) return;
    whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
    whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;

    return false;
    }


    If I replace the function dd(e) in mlayer.html file the layer is visible completly(100% you con't hide the layer ) on the screen, but it is not moving properly.

    function dd(e){
    if (!ddEnabled) return;

    var Xposition = isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
    if(Xposition >= 0 && (Xposition+whichDog.offsetWidth) < document.body.clientWidth)
    whichDog.style.left= Xposition;
    var Yposition = isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
    if(Yposition >= 0 && (Yposition+whichDog.offsetHeight) < document.body.clientHeight)
    whichDog.style.top= Yposition;
    if((Xposition)==0 && (Yposition) == 0){
    whichDog.style.left = 1;
    whichDog.style.top = 1;
    }
    return false;
    }

    Please let me know the solution for this.
    Attached Files Attached Files

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,718
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    http://www.quirksmode.org/js/events_properties.html has a script for correctly determining the mouse coordinates that should help.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •