Javascript新手,有人可以逐行解释这个代码吗?

Xai*_*oft 3 javascript

我使用此代码来保持滚动位置,并且不知道它的含义.如果有人有时间,你能否为我提供一步一步解释它在做什么.这里是:

<script language="javascript"  type="text/javascript">
    var xPos, yPos;
    var prm = Sys.WebForms.PageRequestManager.getInstance();

        function BeginRequestHandler(sender, args) {

        if ($get('<%=lstAuctions.ClientID %>') != null) {

            xPos = $get('<%=lstAuctions.ClientID %>').scrollLeft;
            yPos = $get('<%=lstAuctions.ClientID %>').scrollTop;
        }
    }

    function EndRequestHandler(sender, args) {

        if ($get('<%=lstAuctions.ClientID %>') != null) {

            $get('<%=lstAuctions.ClientID %>').scrollLeft = xPos;
            $get('<%=lstAuctions.ClientID %>').scrollTop = yPos;
        }
    }

    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);

</script>
Run Code Online (Sandbox Code Playgroud)

Tom*_*nto 7

var xPos, yPos; // global variable declaration
var prm = Sys.WebForms.PageRequestManager.getInstance(); // Some webforms javascript manager

/*
* Begin function with 2 arguments
*/
function BeginRequestHandler(sender, args) {

    // check if the element generated by .net with id 'lstAuctions.ClientID' exists
    if ($get('<%=lstAuctions.ClientID %>') != null) {

        // get its scroll left and top position and
        // assign it to the global variables
        xPos = $get('<%=lstAuctions.ClientID %>').scrollLeft;
        yPos = $get('<%=lstAuctions.ClientID %>').scrollTop;
    }
}

/*
* this method gets executed last, it uses the 
* already set global variables to assign the old scrollpositions again
*/
function EndRequestHandler(sender, args) {

    if ($get('<%=lstAuctions.ClientID %>') != null) {
        // assign the previous scroll positions
        $get('<%=lstAuctions.ClientID %>').scrollLeft = xPos;
        $get('<%=lstAuctions.ClientID %>').scrollTop = yPos;
    }
}

// first function gets executed on the beginning of a request
prm.add_beginRequest(BeginRequestHandler);
// second function gets executed on the end of the request
prm.add_endRequest(EndRequestHandler);
Run Code Online (Sandbox Code Playgroud)