参考:

https://blog.csdn.net/leijie0322/article/details/80664554

https://www.cnblogs.com/jpfss/p/9106209.html

需求是要求在图片上添加一个动画效果,可以位置、颜色、大小等参数,

1、在原有的图片上增加一个动画层、

2、动态更换动画参数

3、删除之前加载的动画,更新动画。

      <div
v-else
@mousedown="move"
@touchstart="phonetouchstart"
@touchmove="phonetouchmove"
@touchend="phonetouchend"
align="justify"
class="img3dmodels"
>
<img id="floormodels" :src="img_url" />
<div id="animation_div"></div> //这里就是动画层了 </div>

添加div

    setanimationparameter(op, parameter) {
// 创建动画var divs = document.createElement("div") // 创建div
var cass = document.createAttribute("class"); //创建class定义
cass.value = "animation"; //添加class
divs.setAttributeNode(cass) //div绑定class
var style = document.createAttribute("style"); // 创建style
divs.setAttributeNode(style); // 绑定style divs.style.width = parameter.w;
divs.style.height = parameter.h;
divs.style.left = parameter.x;
divs.style.top = parameter.y;
divs.style.backgroundColor = parameter.color;
op.appendChild(divs) // 添加到动画层 },

清空div

    removeanimation(){
//清空动画、清空动画层内所有的元素
let op = document.getElementById("animation_div");
op.innerHTML =''
},

执行代码

setanimation(parameter,imgIndex) {
let op = document.getElementById("animation_div");
this.removeanimation()
// 楼栋名称、底图、位置、大小、形状、显示隐藏
// parameter : 动画参数
// imgIndex : 展示底图名称
// console.log(parameter)
this.img_url = `${this.imgpwd}${this.filename}${this.prefix}${imgIndex}.png`; if(parameter){
if (parameter.length){
for (let index = 0; index < parameter.length; index++) {
const element = parameter[index];
this.setanimationparameter(op,element);
}
}else{
this.setanimationparameter(op,parameter);
}
console.log("更换动画");
}else{
console.log('动画参数为空')
} },

JavaScript 原生控制元素添加删除的更多相关文章

  1. JavaScript DOM方法表格添加删除

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...

  2. 用JQuery动态为选中元素添加/删除类

    在做一些tab页功能时,我们经常会见到如下样式: 即当选中一个元素时,在此元素下会添加相应的类,以示区别.今天就研究了一下如何用JQuery实现此效果. 1. HTML代码 <a id=&quo ...

  3. 01 使用JavaScript原生控制div属性

    写在前面: 因对前端开发感兴趣,于是自学前端技术,现在已经会HTML.CSS.JavaScript基础技术.但水平处于小白阶段,在网上找一些小项目练练手,促进自己的技术成长.文章记录自己的所思所想,以 ...

  4. JavaScript在div后添加删除div

    var idd = 'str'; $('.task-done-detail-content-p7').click(function () { var id = this.id; if(idd !== ...

  5. 在jinja2的页面中使用javascript对页面元素进行删除

    以对用户注册信息的审核为例. 后端的代码为: #encoding=utf-8 class RegisterCheck(system.page): '''注册信息审核''' path = "/ ...

  6. javascript原生获取元素的方法对比

    document.getElementsByTagName(li)获取的是数组,要获取指定值,需在后面加[0],[1]等,即document.getElementsByTagName(li)[0] d ...

  7. JavaScript实现,控制一个文本框只能输入正整数,如输入不符合条件则文本框全部字体标红

    腾讯2014年研发职位笔试题Web前端方向简单题第一题. 代码: <html> <head> <title>test JavaScript</title> ...

  8. 用Javascript动态添加删除HTML元素实例 (转载)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. JavaScript HTML DOM---遗漏知识再整理(向html添加/删除元素,改变内容和css)

    1.  HTML DOM 改变 HTML 内容:(HTML DOM 允许 JavaScript 改变 HTML 元素的内容.) (1)改变 HTML 输出流 在 JavaScript 中,docume ...

随机推荐

  1. Fiddler抓包实用非常详细,学会不要去做坏事~

    为什么要先学fiddler?学习接口测试必学http协议,如果直接先讲协议,我估计小伙伴们更懵,为了更好的理解协议,先从抓包开始.结合抓包工具讲http协议更容易学一些. 抓firefox上https ...

  2. FirstGradle

    一.导入依赖 二.build.gradle 整合SpringBoot plugins { id 'java' } group 'com.qiang' version '1.0.0-SNAPSHOT' ...

  3. ITIL学习笔记——ITIL入门小知识

    1. 什么是ITIL? ITIL即IT基础架构库(Information Technology Infrastructure Library)由英国政府部门CCTA(Central Computing ...

  4. springboot 2.0 整合 RestTemplate

    首先导入springboot 的 web 包 <dependency> <groupId>org.springframework.boot</groupId> &l ...

  5. JavaWeb之HttpSession

    时间:2016-11-17 22:33 --HttpSession一.HttpSession概述    1.HttpSession是由JavaWeb提供的,用来进行会话跟踪的类.    2.sessi ...

  6. Vue.JS快速上手(Vue-router 实现SPA 开发)

    一.什么是路由 URL -> 映射 -> 组件 Hash+onhashchange History.pushstate+replaceState+onpopstate 二.准备工作 组件 ...

  7. Android系统编程入门系列之应用内键值对数据的简单保存

    在应用程序间及与用户的通信交互过程中,会产生并传递一系列数据.针对这些数据,有部分是只在应用程序中使用的缓存数据,还有一部分是在不同位置多次或长时间使用的持久化数据. 对于缓存数据来说,通常以代码中定 ...

  8. css之px、em、rem

    rem是css3新定义的设置字体大小属性,常用的两种字体大小设置有下面2种:1. px为单位2.em为单位(百分比用法跟em类似) PX为单位 在Web页面初期制作中,我们都是使用"px&q ...

  9. JDK、JRE、JVM的基本介绍

    一 .Java三大版本 JavaSE 标准版(桌面程序.控制台开发-) JavaWE 嵌入式开发(手机.家电-) JavaEE 企业开发(web端.服务器开发-) 二.JDK.JRE.JVM区别 JD ...

  10. Excel vba call Python script on Mac

    How can I launch an external python process from Excel 365 VBA on OSX? It took me a while, but I fig ...