<?xml version="1.0" encoding="utf-8"?>

<snippet name = "将层移动到鼠标位置" description = "用于使指定的层显示在访问者的当前鼠标指针所在位置的代码。" preview="code" type="block">

<insertText location="beforeSelection">

<![CDATA[// * Dependencies * 

// this function requires the following snippets:

// JavaScript/readable_MM_functions/findObj

// JavaScript/readable_MM_functions/showHideLayers

// JavaScript/events/getMouseLoc

function moveLayerToMouseLoc(theLayer, offsetH, offsetV)

{

  var obj;

  if ((findObj(theLayer))!=null)

  {

    if (document.layers)  //NS

    {

      document.onMouseMove = getMouseLoc;

      obj = document.layers[theLayer];

      obj.left = mLoc.x +offsetH;

      obj.top  = mLoc.y +offsetV;

    }

    else if (document.all)//IE

    {

      getMouseLoc();

      obj = document.all[theLayer].style;

      obj.pixelLeft = mLoc.x +offsetH;

      obj.pixelTop  = mLoc.y +offsetV;

    }

    showHideLayers(theLayer,'','show');

  }

}

// get mouse location

function Point(x,y) {  this.x = x; this.y = y; }

mLoc = new Point(-500,-500);

function getMouseLoc(e)

{

  if(!document.all)  //NS

  {

    mLoc.x = e.pageX;

    mLoc.y = e.pageY;

  }

  else               //IE

  {

    mLoc.x = event.x + document.body.scrollLeft;

    mLoc.y = event.y + document.body.scrollTop;

  }

  return true;

}

//NS init:

if(document.layers){ document.captureEvents(Event.MOUSEMOVE); document.onMouseMove = getMouseLoc; }

]]>

</insertText>

<insertText location="afterSelection"><![CDATA[]]>

</insertText>

</snippet>

