event duplication bind bug & h5 dataset flag solution
event duplication bind bug & h5 dataset flag solution
https://codepen.io/xgqfrms/full/PaRBEy/
- OK
- bug
demo
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright gildata
*
* @description zoom modules
* @augments
* @example
*
*/
const ZoomModule = () => {
const zoomIO = () => {
// this === e.target;
console.log(`this =`, this);
// undefined ???
// console.log(`this.innerText =`, this.innerText, typeof(this.innerText));
let text = this.innerText;
if (text === "放大") {
this.innerHTML = "缩小";
} else {
this.innerHTML = "放大";
}
// this === e.target;
// console.log(`this =`, this);
// console.log(`this.parentNode =`, this.parentNode);
// console.log(`this.parentNode.parentNode =`, this.parentNode.parentNode);
// console.log(`this.parentNode.parentNode.nextElementSibling =`, this.parentNode.parentNode.nextElementSibling);
// console.log(`this.parentNode.parentNode.parentNode =`, this.parentNode.parentNode.parentNode);
this.parentNode.style.width = "1024px !important";
this.parentNode.style.maxWidth = "1024px !important";
this.parentNode.parentNode.style.width = "1024px !important";
this.parentNode.parentNode.style.maxWidth = "1024px !important";
this.parentNode.parentNode.nextElementSibling.style.width = "1024px !important";
this.parentNode.parentNode.nextElementSibling.style.maxWidth = "1024px !important";
this.parentNode.parentNode.parentNode.classList.toggle(`h5-full-screen`);
};
function zoomIcons() {
console.log(`this =`, this);
if (this.innerText === "放大") {
this.innerHTML = "缩小";
} else {
this.innerHTML = "放大";
}
this.parentNode.style.width = "1024px !important";
this.parentNode.style.maxWidth = "1024px !important";
this.parentNode.parentNode.style.width = "1024px !important";
this.parentNode.parentNode.style.maxWidth = "1024px !important";
this.parentNode.parentNode.nextElementSibling.style.width = "1024px !important";
this.parentNode.parentNode.nextElementSibling.style.maxWidth = "1024px !important";
this.parentNode.parentNode.parentNode.classList.toggle(`h5-full-screen`);
}
let zooms = [...document.querySelectorAll(`[data-zoom="otc-zoom"]`)];
zooms.forEach(
(zoom, i) => {
if (zoom) {
// if (existEvent) ? false : true;
console.log(`zoom.dataset.eventFlag =`, zoom.dataset, zoom.dataset.eventFlag);
let flag = zoom.dataset.eventFlag;
// data-event-flag="false"
if (!flag) {
zoom.addEventListener(`click`, function (e) {
zoomIcons.bind(zoom)();
});
} else {
// do nothing
zoom.dataset.eventFlag = "false";
}
// zoom.addEventListener(`click`, zoomIO);
// zoom.addEventListener(`click`, zoomIO.bind(zoom));
// ES6 ??? this bug
zoom.addEventListener(`click`, function (e) {
// bug ???
// zoomIO === undefined ???
// zoomIO.bind(zoom)();
// zoomIO.bind(this)();
// zoomIO.bind(e.target)();
// zoomIO.call(zoom);
// zoomIO.call(this);
// zoomIO.apply(zoom);
// zoomIO.apply(this);
});
// old
zoom.addEventListener(`click`, function (e) {
// 1. bind return a new function
// 2. call & apply IIFE
// 3. pass args way different
// func.bind(target)();
// bind OK
// zoomIcons.bind(this)();
// zoomIcons.bind(zoom)();
// zoomIcons.bind(e.target)();
// call OK
// zoomIcons.call(zoom);
// zoomIcons.call(this);
// apply OK
// zoomIcons.apply(zoom);
// zoomIcons.apply(this);
});
// zoom.addEventListener(`click`, function (e) {
// console.log(`this =`, this);
// if (this.innerText === "放大") {
// this.innerHTML = "缩小";
// } else {
// this.innerHTML = "放大";
// }
// this.parentNode.style.width = "1024px !important";
// this.parentNode.style.maxWidth = "1024px !important";
// this.parentNode.parentNode.style.width = "1024px !important";
// this.parentNode.parentNode.style.maxWidth = "1024px !important";
// this.parentNode.parentNode.nextElementSibling.style.width = "1024px !important";
// this.parentNode.parentNode.nextElementSibling.style.maxWidth = "1024px !important";
// this.parentNode.parentNode.parentNode.classList.toggle(`h5-full-screen`);
// });
}
}
);
};
const ZoomModules = () => {
function zoomIcons() {
console.log(`this =`, this);
if (this.innerText === "放大") {
this.innerHTML = "缩小";
} else {
this.innerHTML = "放大";
}
this.parentNode.style.width = "1024px !important";
this.parentNode.style.maxWidth = "1024px !important";
this.parentNode.parentNode.style.width = "1024px !important";
this.parentNode.parentNode.style.maxWidth = "1024px !important";
this.parentNode.parentNode.nextElementSibling.style.width = "1024px !important";
this.parentNode.parentNode.nextElementSibling.style.maxWidth = "1024px !important";
this.parentNode.parentNode.parentNode.classList.toggle(`h5-full-screen`);
}
let zooms = [...document.querySelectorAll(`[data-zoom="otc-zoom"]`)];
zooms.forEach(
(zoom, i) => {
if (zoom) {
// if (existEvent) ? false : true;
// console.log(`zoom.dataset =`, zoom.dataset);
console.log(`zoom.dataset.eventFlag =`, zoom.dataset.eventFlag);
let flag = zoom.dataset.eventFlag;
// data-event-flag="false"
if (!flag) {
// if (flag === undefined || flag === "false") {
zoom.addEventListener(`click`, function (e) {
zoomIcons.bind(zoom)();
});
if (flag === undefined) {
zoom.dataset.eventFlag = false;
// zoom.dataset.eventFlag = "false";
console.log(`zoom.dataset =`, zoom.dataset);
console.log(`zoom.dataset.eventFlag =`, zoom.dataset.eventFlag, typeof(zoom.dataset.eventFlag));
}
} else {
// do nothing
}
}
}
);
};
refs
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/dataset
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
event duplication bind bug & h5 dataset flag solution的更多相关文章
- js & 快捷键 & vue bind bug
js & 快捷键 & vue bind bug how to prevent addEventListener bind many times solution dataset &am ...
- vue & lifecycle methods & this bug & ES6 Arrow function & this bind bug
vue & lifecycle methods & this bug ES6 Arrow function & this bind bug bad fetchTableData ...
- Flash TextField selectable bug block TextEvent.Link solution
There is an old version Felx SDK bug(in my case it's Flex SDK v3.3.0.4852) that when TextField.selec ...
- Jquery操作的是内存数据,H5 dataset操作的是dom属性
Jquery操作的是内存数据,H5操作的是dom属性
- bind:tap="onLike" 中不能添加参数 及 dataset 传值
<view bind:tap="onLike({{id}})"></view> //Component "pages/book-detail/bo ...
- ie烦人的bug篇
好多公司都不支持ie6了,基本都是ie8+,就连jq新版本也宣布放弃低版本ie,就不用说那些框架了,不过想用兼容ie的angularjs可以用我司徒大神写的avalon,个人感觉avalon也是比较好 ...
- Tkinter教程之Event篇(3)
本文转载自:http://blog.csdn.net/jcodeer/article/details/1823550 '''Tkinter教程之Event篇(3)''''''11.两个事件同时绑定到一 ...
- jquery 关于event.target使用的几点说明介绍
event.target说明:引发事件的DOM元素. this和event.target的区别js中事件是会冒泡的,所以this是可以变化的,但event.target不会变化,它永远是直接接受事件的 ...
- 浅试 Webview 一app 加载 H5小游戏
整体架构: InventionActivity:实现UI的实例化,基本的按钮Activity之间跳转 GameActivity:实现UI的实例化,Webview的基本使用 MyProgressDial ...
随机推荐
- 唯一ID生成算法剖析
https://mp.weixin.qq.com/s/E3PGP6FDBFUcghYfpe6vsg 唯一ID生成算法剖析 原创 cloudoxou 腾讯技术工程 2019-10-08
- Jenkins部署web项目到Tomcat(热部署)
使用这个方式的话需要tomcat中有初始时Manage这个项目,本质上是通过http://ip:port/manager/html这个地址的上传接口进行上传,进行热部署(需要远程tomcat 必须开启 ...
- Git轻松入门1:本地仓库篇
什么是Git 版本控制系统 首先我们要明白,什么是版本控制系统(version control systems)? 版本控制系统,顾名思义,就是能控制文件处于哪个版本的系统. e.g. 你在博客园里编 ...
- Cobbler 自动化部署 (转载)
https://www.cnblogs.com/linuxliu/p/7668048.html root默认密码为 123456 (建议修改) ks文件 #platform=x86, AMD64, o ...
- $().arr使用
$("#handmoney").attr("readonly","readonly"); 只读 $("img").att ...
- Flink-v1.12官方网站翻译-P007-Data Pipelines & ETL
数据管道和ETL 对于Apache Flink来说,一个非常常见的用例是实现ETL(提取.转换.加载)管道,从一个或多个源中获取数据,进行一些转换和/或丰富,然后将结果存储在某个地方.在这一节中,我们 ...
- Spring学习笔记2
一.什么是AOP 面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.在不影响原来功能代码的基础上,使用动态代理加入自己需要的一些功能(比如权限的验证,事务的控制,日志的记录 ...
- C++ Socket 入门
Socket 入门 前置知识 :计算机网络基础(TCP/IP四层模型) Socket 原意是"插座",在计算机通信领域被翻译为"套接字",以\(\{IP:Por ...
- AcWing 241 楼兰图腾 (树状数组)
在完成了分配任务之后,西部314来到了楼兰古城的西部. 相传很久以前这片土地上(比楼兰古城还早)生活着两个部落,一个部落崇拜尖刀('V'),一个部落崇拜铁锹('∧'),他们分别用V和∧的形状来代表各自 ...
- hdu 6268 Master of Subgraph(点分治+bitset)
You are given a tree with n nodes. The weight of the i-th node is wi. Given a positive integer m, no ...