<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>1</title>
    <style>
        body {
            background: -webkit-linear-gradient(top, rgb(203, 235, 219) 0%, rgb(55, 148, 192) 120%);
            background: -moz-linear-gradient(top, rgb(203, 235, 219) 0%, rgb(55, 148, 192) 120%);
            overflow: hidden;
            font-family: '微软雅黑';
            font-size: 16px;
            height: 1500px;
        }
        .item {
            width: 200px;
            height: 200px;
            line-height: 30px;
            box-shadow: 0 2px 10px 1px rgba(0, 0, 0, 0.2);
            -webkit-box-shadow: 0 2px 10px 1px rgba(0, 0, 0, 0.2);
            -moz-box-shadow: 0 2px 10px 1px rgba(0, 0, 0, 0.2);
        }
        #container p {
            height: 80px;
            margin: 30px 10px;
            overflow: hidden;
            word-wrap: break-word;
            line-height: 1.5;
        }
        #container a {
            position: relative;
            left: 150px;
            color: red;
            font-size: 14px;
        }
        input {
            display: block;
            height: 30px;
            padding: 0 1em;
            line-height: 30px;
            width: 300px;
            margin: 85px auto;
            font-size: 20px;
        }
    </style>
    <script src="jquery-3.4.1.min.js"></script>
    <script>
        (function ($) {
            var container;
            var colors = ['#96C2F1', '#BBE1F1', '#E3E197', '#F8B3D0', '#FFCC00'];
            var createItem = function (text) {
                var color = colors[parseInt(Math.random() * 5, 10)]
                $('<div class="item"><p>' + text + '</p><a href="#">关闭</a></div>').css({ 'background': color }).appendTo(container).drag();
            };
            $.fn.drag = function () {
                var $this = $(this);
                var parent = $this.parent();
                var pw = parent.width();
                var ph = parent.height();
                var thisWidth = $this.width() + parseInt($this.css('padding-left'), 10) + parseInt($this.css('padding-right'), 10);
                var thisHeight = $this.height() + parseInt($this.css('padding-top'), 10) + parseInt($this.css('padding-bottom'), 10);
                var x, y, positionX, positionY;
                var isDown = false;
                var randY = parseInt(Math.random() * (ph - thisHeight), 10);
                var randX = parseInt(Math.random() * (pw - thisWidth), 10);
                parent.css({
                    "position": "relative",
                    "overflow": "hidden"
                });
                $this.css({
                    "cursor": "move",
                    "position": "absolute"
                }).css({
                    top: randY,
                    left: randX
                }).mousedown(function (e) {
                    parent.children().css({
                        "zIndex": "0"
                    });
                    $this.css({
                        "zIndex": "1"
                    });
                    isDown = true;
                    x = e.pageX;
                    y = e.pageY;
                    positionX = $this.position().left;
                    positionY = $this.position().top;
                    return false;
                });
                $(document).mouseup(function (e) {
                    isDown = false;
                }).mousemove(function (e) {
                    var xPage = e.pageX;
                    var moveX = positionX + xPage - x;
                    var yPage = e.pageY;
                    var moveY = positionY + yPage - y;
                    if (isDown == true) {
                        $this.css({
                            "left": moveX,
                            "top": moveY
                        });
                    } else {
                        return;
                    }
                    if (moveX < 0) {
                        $this.css({
                            "left": "0"
                        });
                    }
                    if (moveX > (pw - thisWidth)) {
                        $this.css({
                            "left": pw - thisWidth
                        });
                    }
                    if (moveY < 0) {
                        $this.css({
                            "top": "0"
                        });
                    }
                    if (moveY > (ph - thisHeight)) {
                        $this.css({
                            "top": ph - thisHeight
                        });
                    }
                });
            };
            var init = function () {
                container = $('#container');
                container.on('click', 'a', function () {
                    $(this).parent().remove();
                }).height(($(window).height() - 200) < 0 ? 520 : ($(window).height() - 200))
                    .width(($(window).width() - 200) < 0 ? '100%' : $(window).width());
                var tests = ['能找一份好工作', '日语等级考试通过', '能交上女朋友', '新年来好运', '中大奖'];
                $.each(tests, function (i, v) {
                    createItem(v);
                });
                $('#input').keydown(function (e) {
                    var $this = $(this);
                    if (e.keyCode == '13') {
                        var value = $this.val();
                        if (value) {
                            createItem(value);
                            $this.val('');
                        }
                    }
                });
            };
            $(function () {
                init();
            });
        })(jQuery);
    </script>
</head>
<body>
    <div id="container" style="height:520px;"></div>
    <input id="input" type="text" placeholder="随便说说吧...按回车键发布" />
</body>
</html>

最新文章

  1. Druid监控Mybatis不显示SQL问题
  2. Android反编译(一)之反编译JAVA源码
  3. sublime text 也能矩形选择
  4. Linux基础入门(新版)(实验九-实验十二)
  5. tyvj1018 - 阶乘统计 ——暴力
  6. lucene 索引合并策略
  7. poj3253
  8. CSS 之 内层div填充margin,外层div的背景色不会覆盖该margin
  9. Find the Duplicate Number 解答
  10. svn经常使用命令具体解释(非常全,非常有用)
  11. MySQL Windows版安装详解
  12. ABP公共结构
  13. 利用ZYNQ SOC快速打开算法验证通路(3)——PS端DMA缓存数据到PS端DDR
  14. setenforce: SELinux is disabled解决办法
  15. Java继承和组合
  16. Ubuntu Server16.04 配置网卡
  17. tomcat9 性能调优
  18. Iperf使用方法与参数说明
  19. delphi clientdataset判断某一行值是否存在
  20. 在TQ2440上运行perf,生成Flame Graph

热门文章

  1. 分颜色通道SR的相关论文
  2. 十个Python爬虫武器库示例,十个爬虫框架,十种实现爬虫的方法!
  3. Ideal常用 快捷键
  4. SqlDbx连接oracle(可用)
  5. Elasticsearch删除数据操作,你必须知道的一些坑
  6. IIS中应用Application Request Route 配置负载均衡
  7. 移动应用端的支付宝支付php开发流程
  8. Unity3d NavMeshAgent 寻路问题(1)
  9. Gogs 设置Git钩子实现项目自动部署
  10. CG-CTF 南邮 综合题2