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 ...
随机推荐
- IdentityServer4之Implicit和纯前端好像很配哦
前言 上一篇Resource Owner Password Credentials模式虽然有用户参与,但对于非信任的第三方的来说,使用这种模式是有风险的,所以相对用的不多:这里接着说说implicit ...
- Java通过openOffice实现word,excel,ppt转成pdf实现在线预览
Java通过openOffice实现word,excel,ppt转成pdf实现在线预览 一.OpenOffice 1.1 下载地址 1.2 JodConverter 1.3 新建实体类PDFDemo ...
- C/C++ ===复习==函数返回值问题(集合体==网络)
按值传递 地址传递: 应该明白只有这2种传递,下面讨论函数的按值传递 #include <stdio.h> #include <stdlib.h> int add_rtVal( ...
- Docker --Dockerfile(制作镜像)
Dockerfile Dockerfile 是一个文本格式的配置文件,用户可以使用 Dockerfile 快速创建自定义的镜像 Dockerfile 常用指令 FROM 作用:指定基础镜像,Docke ...
- SpringMvc获取getbean
import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; i ...
- Java-eclipse导入jar包
Java-eclipse导入jar包 方法一:基本步骤式 右键项目属性,选择Property,在弹出的对话框左侧列表中选择Java Build Path,如下图所示:选择Add External JA ...
- HTTPS优化与证书
1.HTTPS性能优化 1.1 HTTPS性能损耗原因 前文讨论了HTTPS原理与优势:身份验证.信息加密与完整性校验等,且未对TCP和HTTP协议做任何修改.但通过增加新协议以实现更安全的通信必然需 ...
- 如何用RabbitMQ实现延迟队列
前言 在 jdk 的 juc 工具包中,提供了一种延迟队列 DelayQueue.延迟队列用处非常广泛,比如我们最常见的场景就是在网购或者外卖平台中发起一个订单,如果不付款,一般 15 分钟后就会被关 ...
- Flink-v1.12官方网站翻译-P021-State & Fault Tolerance-overview
状态和容错 在本节中,您将了解Flink为编写有状态程序提供的API.请看一下Stateful Stream Processing来了解有状态流处理背后的概念. 下一步去哪里? Working wit ...
- allure生成的报告打开后显示loading
allure生成的报告打开后显示loading,怎么办? 1. allure生成报告的命令 1.1.生成测试数据 # 命令格式:pytest 相关参数 指定执行的用例 --alluredir=数据存放 ...