当前位置:网站首页>下载图片功能,全屏功能,复制功能
下载图片功能,全屏功能,复制功能
2022-07-21 22:46:00 【王——小喵】
dispatchEvent(派遣事件):向指定事件目标派发一个事件,并以合适的顺序触发受影响的事件目标。一般的事件触发都是用户进行某些操作时才会触发,而使用dispatchEvent
就可以在代码中手动触发事件了。
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<button id="click">Click me!</button>
</body>
<script type="text/javascript">
window.onload = function(){
var btn = document.querySelector('#click');
//为元素绑定事件监听
btn.addEventListener('click', function(e){
alert('okk!');
}, false);
//创建一个click事件
var event = new Event('click');
//派发事件
btn.dispatchEvent(event);
}
</script>
</html>
下载图片功能
<img
src="@/assets/routeimg.jpg"
id="routeImg"
@click="downloadRouteImg('routeImg', '路由图')"
/>
const downloadRouteImg = (id, nameStr) => {
var oQrcode = document.getElementById(id);
var url = oQrcode.src;
var a = document.createElement("a");
var event = new MouseEvent("click");
// 自定义下载后图片的名称
a.download = nameStr;
a.href = url;
a.dispatchEvent(event);
};
全屏功能
<img
src="@/assets/routeimg.jpg"
id="routeImg"
@click="fullscreenFn('routeImg')"
/>
import screenfull from "screenfull"; //引入全屏
//全屏
const fullscreenFn = (elName) => {
if (screenfull.isEnabled) {
screenfull.request(document.getElementById(elName));
}
};
复制功能
//复制a模块事件
let copyEvent = false; // 开关
const copyTable = () => {
copyEvent = true;
document.execCommand("copy");
};
//复制b模块事件
let copyBasic = false;
const copyBasicTable = () => {
copyBasic = true;
document.execCommand("copy");
};
const initCopy = () => {
document.addEventListener("copy", (event) => {
//复制a模块
if (copyEvent) {
if (event.clipboardData || event.originalEvent) {
var clipboardData =
event.clipboardData || event.originalEvent.clipboardData;
// 拼接数据
let theadStr = [];
for (let i in detailsDecription) {
theadStr.push(detailsDecription[i]);
}
let first = theadStr.join("\t");
let tbodystr = "";
for (let i = 0; i < detailValtarget.length; i++) {
let startstr = "";
Object.keys(detailsDecription).map((key, item) => {
startstr += detailValtarget[i][key] + "\t";
});
let endstr =
startstr.slice(0, startstr.length - 2) == "\t"
? startstr.slice(0, startstr.length - 2)
: startstr;
tbodystr += endstr + "\n";
}
clipboardData.setData(
"text/plain",
(first + "\n" + tbodystr).toString()
);
event.preventDefault();
copyEvent = false; // 关掉开关
ElMessage({
message: "复制成功",
type: "success",
showClose: false,
});
}
}
//复制b模块
if (copyBasic) {
代码同上,只需改 copyBasic = false; // 关掉开关
}
});
};
initCopy();
execCommand方法是执行一个对当前文档/当前选择/给出范围的命令。
处理Html数据时常用.
如下格式:document.execCommand(sCommand[,交互方式, 动态参数]) ,其中:sCommand为指令参数(如下例中的”2D-Position”),交互方式参数如果是true的话将显示对话框,如果为false的话,则不显示对话框(下例中的”false”即表示不显示对话框),动态参数一般为一可用值或属性值(如下例中的”true”)。
document.execCommand("2D-Position","false","true");
/*
*第二个参数最好不要设置为TRUE,否则可能会执行不了
*/
//加粗
function jiacu()
{
document.execCommand("Bold",false,null);
}
//斜体
function xieti()
{
document.execCommand("Italic",false,null);
}
//下划线
function xiahua()
{
document.execCommand("Underline",false,null);
}
//删除线
function shanchu()
{
document.execCommand("StrikeThrough",false,null);
}
//设置字体
function setFontName(param)
{
document.execCommand("FontName",false,param);
document.getElementById("fontUl").style.display="none";
}
//设置字体大小
function setFontSize(param)
{
document.execCommand("FontSize",false,param);
document.getElementById("sizeUl").style.display="none";
}
//设置字体颜色
function setFontColor(param)
{
document.execCommand("ForeColor",false,param)
document.getElementById("fontColor1").style.display="none";
}
//设置背景颜色
function setBackColor(param)
{
document.execCommand("BackColor",false,param)
document.getElementById("bgColor1").style.display="none";
}
//删除文字格式
function removeFormat()
{
document.execCommand("RemoveFormat",false,null);
}
//对齐方式
function duiqiway(param)
{
document.execCommand(param,false,null);
document.getElementById("duiqiUl").style.display="none";
}
//表情
function insertBQ(param)
{
document.execCommand("InsertImage",false,param); //param为图片的url
document.getElementById("bqDiv").style.display="none";
}
//段落
function parag(param)
{
document.execCommand("formatBlock",false,param);
document.getElementById("paraUl").style.display="none";
}
2D-Position 允许通过拖曳移动绝对定位的对象。 AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。 BackColor 设置或获取当前选中区的背景颜色。 BlockDirLTR 目前尚未支持。 BlockDirRTL 目前尚未支持。 Bold 切换当前选中区的粗体显示与否。 BrowseMode 目前尚未支持。 Copy 将当前选中区复制到剪贴板。 CreateBookmark 创建一个书签锚或获取当前选中区或插入点的书签锚的名称。 CreateLink 在当前选中区上插入超级链接,或显示一个对话框允许用户指定要为当前选中区插入的超级链接的 URL。 Cut 将当前选中区复制到剪贴板并删除之。 Delete 删除当前选中区。 DirLTR 目前尚未支持。 DirRTL 目前尚未支持。 EditMode 目前尚未支持。 FontName 设置或获取当前选中区的字体。 FontSize 设置或获取当前选中区的字体大小。 ForeColor 设置或获取当前选中区的前景(文本)颜色。 FormatBlock 设置当前块格式化标签。 Indent 增加选中文本的缩进。 InlineDirLTR 目前尚未支持。 InlineDirRTL 目前尚未支持。 InsertButton 用按钮控件覆盖当前选中区。 InsertFieldset 用方框覆盖当前选中区。 InsertHorizontalRule 用水平线覆盖当前选中区。 InsertIFrame 用内嵌框架覆盖当前选中区。 InsertImage 用图像覆盖当前选中区。 InsertInputButton 用按钮控件覆盖当前选中区。 InsertInputCheckbox 用复选框控件覆盖当前选中区。 InsertInputFileUpload 用文件上载控件覆盖当前选中区。 InsertInputHidden 插入隐藏控件覆盖当前选中区。 InsertInputImage 用图像控件覆盖当前选中区。 InsertInputPassword 用密码控件覆盖当前选中区。 InsertInputRadio 用单选钮控件覆盖当前选中区。 InsertInputReset 用重置控件覆盖当前选中区。 InsertInputSubmit 用提交控件覆盖当前选中区。 InsertInputText 用文本控件覆盖当前选中区。 InsertMarquee 用空字幕覆盖当前选中区。 InsertOrderedList 切换当前选中区是编号列表还是常规格式化块。 InsertParagraph 用换行覆盖当前选中区。 InsertSelectDropdown 用下拉框控件覆盖当前选中区。 InsertSelectListbox 用列表框控件覆盖当前选中区。 InsertTextArea 用多行文本输入控件覆盖当前选中区。 InsertUnorderedList 切换当前选中区是项目符号列表还是常规格式化块。 Italic 切换当前选中区斜体显示与否。 JustifyCenter 将当前选中区在所在格式化块置中。 JustifyFull 目前尚未支持。 JustifyLeft 将当前选中区所在格式化块左对齐。 JustifyNone 目前尚未支持。 JustifyRight 将当前选中区所在格式化块右对齐。 LiveResize 迫使 MSHTML 编辑器在缩放或移动过程中持续更新元素外观,而不是只在移动或缩放完成后更新。 MultipleSelection 允许当用户按住 Shift 或 Ctrl 键时一次选中多于一个站点可选元素。 Open 打开。 Outdent 减少选中区所在格式化块的缩进。 OverWrite 切换文本状态的插入和覆盖。 Paste 用剪贴板内容覆盖当前选中区。 PlayImage 目前尚未支持。 Print 打开打印对话框以便用户可以打印当前页。 Redo 重做。 Refresh 刷新当前文档。 RemoveFormat 从当前选中区中删除格式化标签。 RemoveParaFormat 目前尚未支持。 SaveAs 将当前 Web 页面保存为文件。 SelectAll 选中整个文档。 SizeToControl 目前尚未支持。 SizeToControlHeight 目前尚未支持。 SizeToControlWidth 目前尚未支持。 Stop 停止。 StopImage 目前尚未支持。 StrikeThrough 目前尚未支持。 Subscript 目前尚未支持。 Superscript 目前尚未支持。 UnBookmark 从当前选中区中删除全部书签。 Underline 切换当前选中区的下划线显示与否。 Undo 撤消。 Unlink 从当前选中区中删除全部超级链接。 Unselect 清除当前选中区的选中状态。
边栏推荐
- 如何使用多类型数据预训练多模态模型?
- 华为无线设备配置攻击检测功能
- Typescript - quick start
- 2022大健康产业展,山东大健康展会,健康膳食展,特医食品展
- Join hands with HMS core analysis services to help the efficient growth of games with data
- 超干货!彻底搞懂单工、半双工、全双工的区别与联系
- The graduation project of wechat hotel reservation applet (1) development outline
- 2022 Shandong Health Exhibition, health industry exhibition, DJK China Health Expo, sleep health exhibition
- B端产品经理学习:数据分析-诸葛io、神策数据
- Eventlet collaboration
猜你喜欢
ECCV 2022 | 基于不变特征学习的广义长尾分类
数商云:供应商多场景趋势下,服装企业如何打造灵活应用的SRM管理体系?
华为无线设备配置WIDS和WIPS
【开源的串口可视化工具——Serial Studio】
机器学习-集成学习
Wechat hotel reservation applet graduation project (4) opening report
esp8266模拟输入(ADC)检测问题
Wechat hotel reservation applet graduation design (2) applet function
B-end product manager learning: data analysis - Zhuge IO, Shence data
百度飞桨EasyDL X 韦士肯:看轴承质检如何装上“AI之眼”
随机推荐
数据类型与变量
How does am5se-is anti islanding protection device solve the impact in the process of distributed photovoltaic power generation?
Daily question-leetcode814-binary tree pruning recursion
el-pinut number取消数字操作符号
What are the characteristics of ball screen projection with different implementation methods
点绕网格中心顺时针旋转 90° 180° 270°坐标的变化
Acl-ijcai-sigir top conference paper report meeting (AIS 2022) Note 2: analysis and interpretability
Differential privacy budget optimization method based on deep learning in Internet of things environment
Thread pool configuration asynchronous orchestration completable future
【力扣】相对名次
Wechat hotel reservation applet graduation design (2) applet function
MD5 & MD5 salt value encryption
The point rotates clockwise around the center of the grid by 90 ° 180 ° 270 ° coordinate change
2022.07.18
Wechat hotel reservation applet graduation project (4) opening report
OAuth2.0
并发程序的噩梦——数据竞争
: style usage in projects
ACL-IJCAI-SIGIR頂級會議論文報告會(AIS 2022)筆記1:推薦系統
Three methods of JS intercepting strings