dragpanel.aspx

来自「AJAX 应用 实现页面的无刷新」· ASPX 代码 · 共 118 行 · 第 1/3 页

ASPX
118
字号
        // Fire an onmouseup event at point (x,y)
        function mouseUp(element, x, y) {
            return function() {
                var e = testHarness.getDocument().createEvent('MouseEvents');
                e.initMouseEvent('mouseup', true, false, window, 0, x, y, x, y, false, false, false, false, 0, null);
                element.dispatchEvent(e);
            };
        }

        // Use mouse events to drag an element from (fromX,fromY) to (toX,toY)
        function drag(element, fromX, fromY, toX, toY) {
            return function() {
                if (!testHarness.getDocument().createEvent) {
                    testHarness.cancel('This test can only be run on a browser that supports document.createEvent (such as Firefox)');
                    return;
                }
                mouseDown(element, fromX, fromY)();
                mouseMove(element, toX, toY)();
                mouseUp(element, toX, toY)();
            };
        }

        // Register the tests
        function registerTests(harness) {
            testHarness = harness;

            // Get the controls on the page
            panel = testHarness.getElement('ctl00_ContentPlaceHolder1_Panel1');

            var test = testHarness.addTest('Initial Location');
            test.addStep(checkInitialPosition);

            test = testHarness.addTest('Drag');
            test.addStep(checkInitialPosition);
            test.addStep(drag(panel, 10, 10, 100, 100), 1000, checkHasMoved(0, 0));
        }
    </script>
</asp:Content>

⌨️ 快捷键说明

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