web 给大家分享一个好玩的东西,也许你那块就用的到
先看效果:



就这个效果。当你点击右上角的删除按钮,会删除掉item1。
上代码:
<!DOCTYPE html>
<html> <head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.central {
/* 利用绝对定位和flex实现居中 */
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
margin: auto;
width: 50%;
height: 80%;
background-color: antiquewhite;
/* 居中效果结束 */ display: flex;
flex-direction: column;
/* 垂直排列 */
/* 与justify-content相同的方式在侧轴方向上将当前行上的弹性元素对齐。也就是上下居中 */
align-items: center;
/* 居中排列,水平方向 */
justify-content: center;
} #pop_div {
background-color: #F6F6F6;
width: 60px;
height: 60px;
border-radius: 30px; /* 用边框半径实现圆形div */
text-align: center;
line-height: 60px;
outline: none;
font-size: 30px;
color: #C4C6C7;
} #pop_div:hover {
cursor: pointer; /* 当鼠标移动到标签上是,自动变成手指形状 */
} .add_item {
background-color: #F6F6F6;
width: 60px;
height: 60px;
border-radius: 30px;
text-align: center;
line-height: 60px;
outline: none;
font-size: 10px;
color: #C4C6C7;
} .btn_delete {
position: relative;
float: right;
right: 0px;
top: 0px;
width: 20px;
height: 20px;
border-radius: 10px;
outline: none;
border: none;
cursor: pointer;
} .hide_div {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
margin: auto;
width: 100%;
height: 100%; display: none; /* 显示方式:none(标签不显示) */
background-color: rgba(194, 195, 201, 0.7); /* 实现半透明北京,0.7代表不透明度 */
} .hide_div div {
cursor: pointer;
}
</style>
</head> <body>
<div class="central">
<div id="panel"></div>
<div id="pop_div" title="添加" onclick="popDiv();">+</div>
</div>
<div id="hide_div" class="hide_div">
<div id="item1" onclick="itemClick('item1');">item1</div>
<div id="item2" onclick="itemClick('item2');">item2</div>
<div id="item3" onclick="itemClick('item3');">item3</div>
<div id="item4" onclick="itemClick('item4');">item4</div>
<div id="item5" onclick="itemClick('item5');">item5</div>
</div>
<script>
function popDiv() {
// alert("将要弹出一个div");
var vardiv = document.getElementById("hide_div");
vardiv.style.display = "flex";
vardiv.style.flexDirection = "column";
vardiv.style.justifyContent = "center";
vardiv.style.alignItems = "center";
// vardiv.onclick = itemClick;
} function itemClick(item) {
var text = document.getElementById(item).innerHTML; /* 获取元素html属性返回string */
// alert(text);
var vardiv = document.getElementById("hide_div");
vardiv.style.display = "none";
addElementToHtml(text);
} var index = 0;
function addElementToHtml(text) {
// 判断是否已经存在这个id的标签
if (null != document.getElementById(text + "_p")) {
alert('不能重复添加...');
return;
} // 创建一个p标签,设置属性
var p = document.createElement('p');
p.id = text + "_p";
p.innerHTML = text;
p.className = "add_item"; // 创建一个input标签,设置属性
var btnDel = document.createElement('input');
btnDel.type = 'button';
btnDel.value = '×';
btnDel.title = "删除";
btnDel.className = "btn_delete"; // 绑定删除按钮删除事件
btnDel.onclick = function () {
// alert("将删除" + this.parentNode.id + "标签及子标签...");
this.parentNode.parentNode.removeChild(this.parentNode); /* 首先要找到要删除节点的父节点,然后通过父节点才能删除自己 */
}; // 添加删除按钮到p标签中
p.appendChild(btnDel); var panel = document.getElementById("panel");
panel.appendChild(p);
}
</script>
</body> </html>
web 给大家分享一个好玩的东西,也许你那块就用的到的更多相关文章
- C# PDF Page操作——设置页面切换按钮 C# 添加、读取Word脚注尾注 C#为什么不能像C/C++一样的支持函数只读传参 web 给大家分享一个好玩的东西,也许你那块就用的到
C# PDF Page操作——设置页面切换按钮 概述 在以下示例中,将介绍在PDF文档页面设置页面切换按钮的方法.示例中将页面切换按钮的添加分为了两种情况,一种是设置按钮跳转到首页.下页.上页或者 ...
- 发现一个好玩的东西 Web Scraper
是一个 Chrome 的扩展程序,机智的小爬虫
- 2. web前端开发分享-css,js进阶篇
一,css进阶篇: 等css哪些事儿看了两三遍之后,需要对看过的知识综合应用,这时候需要大量的实践经验, 简单的想法:把qq首页全屏另存为jpg然后通过ps工具切图结合css转换成html,有无从下手 ...
- 分享一个刷网页PV的python小脚本
下面分享一个小脚本,用来刷网页PV. [root@huanqiu ~]# cat www.py #!/usr/bin/python# coding: UTF-8import webbrowser as ...
- Git.Framework 框架随手记-- 分享一个"比较垃圾"的项目
本文主要分享一个Git.Framework 开发的一个项目的部分源码,此项目代码"比较垃圾",所以请各位码农,码畜,码神,码圣勿喷!发此文只为记录工作问题以及分享问题! 一. 项目 ...
- 文件系统:介绍一个高大上的东西 - 零基础入门学习Python030
文件系统:介绍一个高大上的东西 让编程改变世界 Change the world by program 接下来我们会介绍跟Python的文件相关的一些十分有用的模块.模块是什么?不知大家对以下代码还有 ...
- 分享一个c#写的开源分布式消息队列equeue
分享一个c#写的开源分布式消息队列equeue 前言 equeue消息队列中的专业术语 Topic Queue Producer Consumer Consumer Group Broker 集群消费 ...
- 【开源.NET】 分享一个前后端分离的轻量级内容管理框架
开发框架要考虑的面太多了:安全.稳定.性能.效率.扩展.整洁,还要经得起实践的考验,从零开发一个可用的框架,是很耗时费神的工作.网上很多开源的框架,为何还要自己开发?我是基于以下两点: 没找到合适的: ...
- [UWP]分享一个基于HSV色轮的调色板应用
1. 前言 上一篇文章介绍了HSV色轮,这次分享一个基于HSV色轮的调色板应用,应用地址:ColorfulBox - Microsoft Store 2. 功能 ColorfulBox是Adobe 色 ...
随机推荐
- Python unittest excel数据驱动
安装xlrd 下载地址:https://pypi.python.org/pypi/xlrd 安装ddt 下载地址:https://pypi.python.org/pypi/ddt/1.1.0 clas ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- Delphi7 [Fatal Error] ClassPas.pas(8): File not found: 'DesignIntf.dcu'
Delphi7 [Fatal Error] ClassPas.pas(8): File not found: 'DesignIntf.dcu' Add path to Project>Optio ...
- spring security+cas(cas proxy配置)
什么时候会用到代理proxy模式? 举一个例子:有两个应用App1和App2,它们都是受Cas服务器保护的,即请求它们时都需要通过Cas 服务器的认证.现在需要在App1中通过Http请求访问App2 ...
- The Process of Google Hiring
[The Process of Google Hiring] 1.keynote 1: The Google hiring process is designed to hire the most t ...
- ora-01045错误的解决办法
问题: 在用PL/SQL进行登录时,出现:”ora-01045 :user system lacks create session privilege; logon denied”. 原因:该用户没有 ...
- Unity中的网格与材质球合并
http://blog.csdn.net/dardgen2015/article/details/51517860
- php 共享内存学习(APC扩展)
问题:希望可以在进程间共享变量,为共享数据提供快速访问 解决方案:使用APC扩展的数据存储功能 (cli模式下没有作用) //获取原来的值 $population = apc_fetch('popul ...
- CSS中float和Clear的使用
CSS中float和Clear的使用 本文和大家重点讨论一下CSS中Float和Clear属性的使用,一个float对象可以居左或居右,一个设置为float的对象,将根据设置的方向,左移或右移到其父容 ...
- 利用FFmpeg转压视频的说明
当我们制作视频的时候,录制完成的视频往往很大,很容易超过50M,上传的时候会很慢.下面将相关技巧说明如下(转载,版权属于原作者所有). 利用FFmpeg转压视频的说明 录制介绍视频时可以用尽可能高的分 ...