SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Paraguay - Asuncion
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Moving a DIV into the screen view...

    Hi there,

    Objective:
    When my page loads the DIV is 'hidden' and its left="0" and top="0"
    I change the visibility of my DIV from 'hidden' to 'visible' when my mouse moves over an image AND with a function I move it to my current cursor location.

    Problem:
    My DIV gets a little big and doesn't show all its content in the current screen view.

    Result:
    User needs to scroll the browser window to view the contents of my DIV

    Question:
    How can I get that DIV to move to my cursor location BUT also move so that the user doen't need to scroll the browser?

    Thanking you in Advance!!

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi 4u2nv, Welcome to SitePoint Forums!

    Is your page online so we can take a look?

    In general...
    Code:
    function showDiv()
    {
      // get mouse y coord (mY)
      // get height of div (divHeight)
      // get inner height of window (clientHeight)
      // get amount of vertical window scroll (scrollTop)
      // calculate div's new y coord:
      if (mY + divHeight > scrollTop + clientHeight)
      {
        y = scrollTop + clientHeight - divHeight;
      }
      else
      {
        y = mY;
      }
      // get mouse x coord (mX)
      // get width of div (divWidth)
      // get inner width of window (clientWidth)
      // get amount of horizontal window scroll (scrollLeft)
      // calculate div's new x coord:
      if (mX + divWidth > scrollLeft + clientWidth)
      {
        x = scrollLeft + clientWidth - divWidth;
      }
      else
      {
        x = mX;
      }
      
      // now position the div at the point (x,y)
    }

  3. #3
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Paraguay - Asuncion
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the welcome MikeFoster!

    Thanks for the help, the code makes sense... I'll give it a go later today.
    Last edited by 4u2nv; Nov 11, 2006 at 08:44.


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
  •