夜微凉、的博客

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  76 随笔 :: 24 文章 :: 22 评论 :: 24万 阅读

代码:

复制代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <title> New Document </title>
    <script src="https://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"></script>
</head>

<body>
    <style>
        #show {
            width: 250px;
            height: 300px;
            background-color: orange;
            cursor: pointer;
            position: absolute;
            top: 100px;
        }
    </style>
    <div id="show">
        <p>窗前明月光</p>
    </div>
    <script>

        $("#show").mousedown(function (event) {
            var offset = $("#show").offset();
            x1 = event.clientX - offset.left;
            y1 = event.clientY - offset.top;

            $(document).mousemove(function (event) {
                if (!isNaN(event.clientX) && !isNaN(event.clientY)) {
                    $("#show").css("left", (event.clientX - x1) + "px");
                    $("#show").css("top", (event.clientY - y1) + "px");
                }
            });
            $("#show").mouseup(function (event) {
                $(document).unbind("mousemove");
            });
        });

        // $(document).keydown(function (event) {
        //     var keyCodeValue = event.keyCode;
        //     var offsetValue = $("#show").offset();

        //     if (keyCodeValue == 46) {
        //         $("#show").remove();
        //     }
        //     switch (keyCodeValue) {
        //         case 37: $("#show").offset({ left: (offsetValue.left - 1) });
        //             break;
        //         case 38: $("#show").offset({ top: (offsetValue.top - 1) });
        //             break;
        //         case 39: $("#show").offset({ left: (offsetValue.left + 1) });
        //             break;
        //         case 40: $("#show").offset({ top: (offsetValue.top + 1) });
        //             break;
        //     }
        // });
    </script>
</body>

</html>
复制代码

 

posted on   夜、微凉  阅读(473)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
历史上的今天:
2019-03-05 MSMQ消息队列
点击右上角即可分享
微信分享提示