⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 movable.htc

📁 Flash电子相册 v1.2 Build 1108完整版本下载
💻 HTC
📖 第 1 页 / 共 2 页
字号:
//-----------------------------------------------------------------------------

function snapToGrid()
{
    //  Call MoveElement to move the piece
    MoveElement(offsetLeft, offsetTop, true);
}


//+----------------------------------------------------------------------------
//
//  Function:       SetBoundary
//
//  Description:    Move the element within the boundaries specified by the
//                  mvBoundary properties.
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function SetBoundary()
{
    //  Obey right boundary
    if (style.mvBoundaryRight != null
        && style.mvBoundaryRight < style.posLeft + offsetWidth)
    {
        style.left = style.mvBoundaryRight - offsetWidth;
    }
    
    //  Obey left boundary
    if (style.mvBoundaryLeft
        && style.mvBoundaryLeft > style.posLeft)
    {
        style.left = style.mvBoundaryLeft;
    }
    
    //  Obey bottom boundary
    if (style.mvBoundaryBottom
        && style.mvBoundaryBottom < style.posTop + offsetHeight)
    {
        style.top = style.mvBoundaryBottom - offsetHeight;
    }
    
    //  Obey top boundary
    if (style.mvBoundaryTop
        && style.mvBoundaryTop > style.posTop)
    {
        style.top = style.mvBoundaryTop;
    }
    
    //  If the element is snapable, call snapToGrid to snap it.
    if (snapable == true || snapable == "true") snapToGrid();
}


//+----------------------------------------------------------------------------
//
//  Function:       MoveElement
//                  
//  Description:    Moves the piece to the specified coordinates.  If any
//                  of the mvGrid or mvBoundary properties are set, they are
//                  enforced.
//
//  Arguments:      iNewX - Left position to move the piece to
//                  iNewY - Top position to move the piece to
//                  bSnapTo - called explicitly from snapToGrid()
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function MoveElement(iNewX, iNewY, bSnapTo)
{
    if (direction != "vertical" && iNewX != null)
    {
        //
        //  If the piece is snapable, then both the grid and the boundary
        //  (if one exists) have to be enforced
        //
        if ((snapable == true || snapable == "true" 
            || bSnapTo == true) && style.mvGridCols != null)
        {
            //  Find the closest grid
            var iSnapX = (Math.round(iNewX/style.mvGridCols)) * style.mvGridCols;

            //  If the piece is outside of the boundaries, put on a grid inside
            if (style.mvBoundaryLeft != null
                && iSnapX < style.mvBoundaryLeft)
            {
                iSnapX = (Math.ceil(style.mvBoundaryLeft/style.mvGridCols))
                    * style.mvGridCols;
            }
            else if (style.mvBoundaryRight != null
                && iSnapX > style.mvBoundaryRight - offsetWidth)
            {
                iSnapX = (Math.floor((style.mvBoundaryRight-offsetWidth)
                    /style.mvGridCols)) * style.mvGridCols;
            }
            iNewX = iSnapX;
        }
        //
        //  Otherwise, if the piece has just a boundary, then it needs to be
        //  enforced.  If the piece is outside the boundaries, put it inside
        //
        else if (style.mvBoundaryLeft != null
            && iNewX < style.mvBoundaryLeft)
        {
            iNewX = style.mvBoundaryLeft;
        }
        else if (style.mvBoundaryRight != null
            && iNewX > style.mvBoundaryRight - offsetWidth)
        {
            iNewX = style.mvBoundaryRight - offsetWidth;
        }

        //  Put the piece in it's (possibly adjusted) position
        style.left = iNewX;
    }

    if (direction != "horizontal" && iNewY != null)
    {
        //
        //  If the piece is snapable, then both the grid and the boundary
        //  (if one exists) have to be enforced
        //
        if ((snapable == true || snapable == "true" 
            || bSnapTo == true) && style.mvGridRows != null)
        {
            //  Find the closest grid
            var iSnapY = (Math.round(iNewY/style.mvGridRows)) * style.mvGridRows;

            //  If the piece is outside of the boundaries, put on a grid inside
            if (style.mvBoundaryTop != null
                && iSnapY < style.mvBoundaryTop)
            {
                iSnapY = (Math.ceil(style.mvBoundaryTop/style.mvGridRows))
                    * style.mvGridRows;
            }
            else if (style.mvBoundaryBottom != null 
                && iSnapY > style.mvBoundaryBottom - offsetHeight)
            {
                iSnapY = (Math.floor((style.mvBoundaryBottom-offsetHeight)
                    /style.mvGridRows)) * style.mvGridRows;
            }
            
            iNewY = iSnapY;
        }
        //
        //  Otherwise, if the piece has just a boundary, then it needs to be
        //  enforced.  If the piece is outside the boundaries, put it inside
        //
        else if (style.mvBoundaryTop != null
            && iNewY < style.mvBoundaryTop)
        {
            iNewY = style.mvBoundaryTop;
        }
        else if (style.mvBoundaryBottom != null
            && iNewY > style.mvBoundaryBottom - offsetHeight)
        {
            iNewY = style.mvBoundaryBottom - offsetHeight;
        }
    
        //  Put the piece in it's (possibly adjusted) position
        style.top = iNewY;
    }
}


//+----------------------------------------------------------------------------
//
//  Function:       DoMouseDown 
//
//  Description:    Begins the moving process.
//
//  Arguments:      none
//
//  Returns:        true if the movable property is set to false 
//
//-----------------------------------------------------------------------------

function DoMouseDown()
{
    //  If the piece is not movable, don't allow it to be moved
    if (movable == false || movable == "false") return true;
    
    //if (Selectable == true || Selectable == "true")
    //{
		var sTag = window.event.srcElement.tagName.toLowerCase();
		//alert(sTag);
		
		//if (sTag == "input" || sTag == "textarea" ||
		//	sTag == "button" || sTag == "a" ||
		//	sTag == "select" || sTag == "object")
		
		if (sTag == "input" || sTag == "textarea" || sTag=="span" ||
		    sTag == "button" || sTag == "a" ||
		    sTag == "select" || sTag == "object" ||  sTag == "submit" )
	
		return false;
    //}
        
    //  Capture the mouse
    setCapture();
    
    //  Set the zIndex to 1000 to put it over other elements while it's moved
	style.zIndex = 1000;

    //
    //  Determine the difference between the mouse click on the element and
    //  the top left corner	
    //
	iOffsetX = window.event.x - element.style.pixelLeft;
	iOffsetY = window.event.y - element.style.pixelTop;

    //  Start tracking the mousemove
	attachEvent ("onmousemove", DoMouseMove);

	dragstart.fire();
}	


//+----------------------------------------------------------------------------
//
//  Function:       DoMouseMove
//
//  Description:    Moves the element.
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function DoMouseMove()
{
	if (direction != "vertical") 
	{
	    //  Set position based on mouse movement
	    var iNewX = window.event.x - iOffsetX;
    
        //  Obey left boundary
	    if (style.mvBoundaryLeft != null
	        && iNewX < style.mvBoundaryLeft)
	    {
	        iNewX = style.mvBoundaryLeft;
	    }
	    
	    //  Obey right boundary
	    if (style.mvBoundaryRight != null
	        && iNewX > style.mvBoundaryRight - offsetWidth)
	    {
	        iNewX = style.mvBoundaryRight - offsetWidth;
	    }

        //  Place element
	    style.left = iNewX;
	}

	if (direction != "horizontal")
	{
	    //  Set position based on mouse movement
	    var iNewY = window.event.y - iOffsetY;
	    
	    //  Obey top boundary
	    if (style.mvBoundaryTop != null 
	        && iNewY < style.mvBoundaryTop)
	    {
	        iNewY = style.mvBoundaryTop;
	    }
	    
	    //  Obey bottom boundary
	    if (style.mvBoundaryBottom != null 
	        && iNewY > style.mvBoundaryBottom - offsetHeight)
	    {
	        iNewY = style.mvBoundaryBottom - offsetHeight;
	    }
	    
	    //  Place element
	    style.top = iNewY;
	}
	
	drag.fire();
}


//+----------------------------------------------------------------------------
//
//  Function:       DoMouseUp
//
//  Description:    Ends the moving process.
//
//  Arguments:      none
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function DoMouseUp()
{
    //  Return the zIndex to its previous value
	style.zIndex = normZindex;

    //  Stop tracking the onmousemove event
	detachEvent ("onmousemove", DoMouseMove);
	
	//  Release the mouse
	releaseCapture();

    //  If it's snapable, snap it now
	if (snapable == "true" || snapable == true) snapToGrid();

    //
    //  Create a click on the srcElement. If the selectable property is set
    //  to true, this will allow clicks on links, etc. to occur
    //
    window.event.srcElement.click();
	
	dragend.fire();
}


//+----------------------------------------------------------------------------
//
//  Function:       DoSelect 
//
//  Description:    If the selectable property is set to false, this function
//                  cancels clicks and drags inside of the element itself.
//
//  Arguments:      none
//
//  Returns:        false (returnValue)
//
//-----------------------------------------------------------------------------

function DoSelect()
{
    if (selectable != "true" && selectable != true)
    {
        window.event.returnValue = false;
    }
}


//+----------------------------------------------------------------------------
//
//  Function:       ReturnError
//
//  Description:    Fires the error event, along with a descriptive text
//                  message.
//
//  Arguments:      sMsg - descriptive text message
//
//  Returns:        nothing
//
//-----------------------------------------------------------------------------

function ReturnError(sMsg)
{
    var oEvent = createEventObject();
    oEvent.setAttribute("error", sMsg);
    error.fire(oEvent);
}

</SCRIPT>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -