首页 > 其他分享 >HTML拖拽API, 看了某位大佬的视频, 有感而发

HTML拖拽API, 看了某位大佬的视频, 有感而发

时间:2023-10-26 17:33:30浏览次数:35  
标签:flex HTML color items API 有感而发 ev display center

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta
    name="viewport"
    content="width=device-width, initial-scale=1.0"
  >
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    .title {
      width: 1000px;
      margin: 100px auto 0;
      display: flex;
      background-color: #ccc;

      .item1 {
        flex: 1;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
      }

      .item2 {
        flex: 2;
        height: 40px;
      }

      .item7 {
        flex: 7;
        height: 40px;
        display: flex;

        .item {
          height: inherit;
          flex: 1;
          display: flex;
          align-items: center;
          justify-content: center;
          font-weight: 700;
        }
      }
    }

    .c1 {
      background-color: blue;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .c2 {
      background-color: orange;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .c3 {
      background-color: green;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .c4 {
      background-color: purple;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .c5 {
      background-color: orangered;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .c6 {
      background-color: teal;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .container {
      width: 1000px;
      margin: 0 auto;
      display: flex;
      background-color: #eee;

      .class_dir {
        flex: 0 0 100px;
        padding: 10px;
      }

      .time_tip {
        flex: 0 0 200px;
        display: flex;
        flex-direction: column;
        align-items: flex-end;


        .time1 {
          height: 160px;
          width: 40px;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          background: #Bbb;

        }

        .time2 {
          height: 160px;
          width: 40px;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          background: #Bbb;
          margin-top: 40px;
        }
      }

      .time_task {
        flex: 0 0 700px;
      }
    }

    .class_dir div {
      width: 100%;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      color: #666;
      margin-bottom: 10px;
      color: #fff;
    }

    .morning,
    .afternoon {
      display: flex;
      flex-wrap: wrap;
    }

    .morning div,
    .afternoon div {
      flex: 0 0 20%;
      width: 140px;
      height: 40px;
      border-top: 1px solid #222;
      border-left: 1px solid #222;
    }

    .morning div:nth-child(5n),
    .afternoon div:nth-child(5n) {
      border-right: 1px solid #222;
    }

    .morning div:nth-child(n + 16),
    .afternoon div:nth-child(n + 16) {
      border-bottom: 1px solid #222;
    }

    .afternoon {
      margin-top: 40px;
    }
  </style>
</head>

<body>
  <div class="title">
    <div class="item1">课程</div>
    <div class="item2"></div>
    <div class="item7">
      <div class="item">周一</div>
      <div class="item">周二</div>
      <div class="item">周三</div>
      <div class="item">周四</div>
      <div class="item">周五</div>
    </div>
  </div>
  <div class="container">
    <div class="class_dir">
      <div
        draggable="true"
        class="c1"
        data-mode="move"
      >政治</div>
      <div
        draggable="true"
        class="c2"
        data-mode="move"
      >高数</div>
      <div
        draggable="true"
        class="c3"
        data-mode="move"
      >音乐</div>
      <div
        draggable="true"
        class="c4"
        data-mode="move"
      >体育</div>
      <div
        draggable="true"
        class="c5"
        data-mode="move"
      >微机</div>
      <div
        draggable="true"
        class="c6"
        data-mode="move"
      >CAD</div>
    </div>
    <div class="time_tip">
      <div class="time1">
        <span>上</span>
        <span style="margin-top: 20px;">午</span>
      </div>
      <div class="time2">
        <span>下</span>
        <span style="margin-top: 20px;">午</span>
      </div>
    </div>
    <div class="time_task">
      <div class="morning">
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
      </div>
      <div class="afternoon">
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
        <div data-mode="receive"></div>
      </div>
    </div>
  </div>

  <script>
    const container = document.querySelector('.container')

    let moveEl = null

    container.addEventListener('dragstart', ev => {
      moveEl = ev.target
    })

    container.addEventListener('dragend', ev => {
      // console.log(ev.target, 'end')
    })

    container.addEventListener('dragenter', ev => {
      // console.log(ev.target, 'enter')
    })

    // 经过的元素, 会一直触发
    container.addEventListener('dragover', ev => {
      ev.preventDefault();
      // console.log(ev, 'over')
    })

    container.addEventListener('drop', ev => {
      const mode = ev.target.getAttribute('data-mode')
      const old = moveEl.getAttribute('data-mode')
      if (old === 'move' && mode === 'receive') {
        const newEl = moveEl.cloneNode(true)
        newEl.setAttribute('data-mode', 'remove')
        ev.target.appendChild(newEl)
      }
      if (old === 'remove' && mode === 'move') {
        moveEl.parentNode.innerHTML = ''
      }
      if (old === 'remove' && mode === 'receive') {
        ev.target.appendChild(moveEl)
      }
    })
  </script>
</body>

</html>

 

标签:flex,HTML,color,items,API,有感而发,ev,display,center
From: https://www.cnblogs.com/fmg0224/p/17789927.html

相关文章

  • 《HTML5秘籍.第2版》高清高质量 原版电子书PDF
    下载:https://pan.quark.cn/s/0284694919cc......
  • 使用fluent api调用https接口时忽略证书异常
    不知道为啥,中文互联网对脱胎于httpclient的fluentapi介绍太少了,遇到问题也不知道怎么查,只能自己研究,于是遇到问题赶紧记下来一般情况下我们使用fluent的get方法调用http接口的方式是这样的Request.get(url).connectTimeout(Timeout.ofMilliseconds(5000)).e......
  • html中如何设置label自动换行
    html中如何设置label自动换行在HTML中,我们经常需要设置label标签,这是一种非常常见且重要的标签。在有些情况下,我们的label标签中的文本可能会超出一行,这时就需要设置自动换行。为了实现在label标签中自动换行,我们需要使用CSS语言中的white-space属性,将其设置为"pre-wrap"或"pre......
  • 「实用技巧」后端如何使用 Eolink Apikit 快速调试接口?
    程序员最讨厌的两件事:写文档别人不写文档写文档、维护文档比较麻烦,而且费时,还会经常出现API更新了,但文档还是旧的,各种同步不一致的情况,从而耽搁彼此的时间,大多数开发人员不愿意写API文档。EolinkApikit为后端工程师提供API文档的创建与自动化生成、快速接口调试、以......
  • html基础之列表
    html的列表在html中列表分为有序列表、无序列表和自定义列表,它们之间有什么相同点和不同之处我们来讲讲。有序列表有序列表的英文单词(orderedlists),所以有序列表的标签为<ol>列表的英文单词(listitem),所以列表内容的标签为<li>,有序列表都是需要<ol>标签和<li>标签相互配合使用......
  • Kafka 生产者API,消费者API,拦截器,流计算
    pom文件如下:<dependencies> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId......
  • html基础内容之表格
    html表格html制作一个表格需要用到以下3中标签。①table标签:双标签用来定义这是一个表格②tr标签:双标签用来定义行数③td标签:双标签用来定义列数如果进行定义一个表格:1<!DOCTYPEhtml>2<htmllang="en">34<head>5<metacharset="UTF-8">6<title>......
  • 甘特图组件DHTMLX Gantt用例 - 如何自定义任务、月标记和网格新外观
    dhtmlxGantt是用于跨浏览器和跨平台应用程序的功能齐全的Gantt图表。可满足项目管理应用程序的所有需求,是最完善的甘特图图表库。本文将为大家揭示DHTMLXGantt自定义的典型用例,包括自定义任务、网格的新外观等,来展示其功能的强大性!用例-新建项目外观、当前月份标记和可折叠网格D......
  • 603-60API资源对象StorageClass、Ceph存储 6.3-6.5
    一、NFS存储使用master-1-230节点做NFS服务器,具体安装步骤参考:https://www.cnblogs.com/pythonlx/p/17766242.html (4.1在master节点搭建NFS)node节点查看NFS挂载目录##showmount-e192.168.1.230Exportlistfor192.168.1.230:/data/kubernetes*/data/nfs_test*......
  • Apipost现已支持连接数据库!
    Apipost提供了数据库连接功能,在接口调试时可以使用数据库获取入参或进行断言校验。目前的Apipost支持:Mysql、SQLSever、Oracle、Clickhouse、达梦数据库、PostgreSQL、Redis、MongoDB8种数据库的连接操作新建数据库连接:在「项目设置」-「公共资源维护」-「连接数据库」中配置需......