Home  >  Article  >  Web Front-end  >  Detailed introduction to the use tutorial of ZeroClipboard

Detailed introduction to the use tutorial of ZeroClipboard

零下一度
零下一度Original
2017-05-11 13:37:322321browse

This article mainly introduces to you in detailJavaScriptrelated information on using ZeroClipboard to operate the clipboard. It has certain reference value. Interested friends can refer to it.

1. ZeroClipboard download address

Provide you with a detailed download address of ZeroClipboard:

Zero Clipboard Open source JavaScript+flash copy library class

Copy and paste website content based on ZeroClipboardJS special effectsSource code

zeroclipboard implemented with js and flash File copied to clipboard

2. Add js reference


3. Initialize plug-in

$(function () {
   InitCopyToClipboard('btnCopyToClipBoard');
 });
//将内容复制到剪切板
function InitCopyToClipboard(btnId) {
ZeroClipboard.setMoviePath("../Assets/js/ZeroClipboard/ZeroClipboard.swf"); //设置flash文件在项目中的位置 
var clip = new ZeroClipboard.Client(); // 新建一个对象

clip.setHandCursor(true);
clip.addEventListener('onmouseup', function (client) { //创建监听 
 // 可以在这儿写一个方法处理相应的事件逻辑
 clip.setText('要复制到剪切板中的内容'); 
});
clip.glue(btnId); //将flash覆盖至指定ID的DOM上

//窗口大小发生变化时从新将flash覆盖至制定的id上,否则位置不对应导致点击时没反应
bind(window, "resize", function () {
  clip.reposition();
});
return false;
}
/************************************ 
* 添加事件绑定 
* @param obj : 要绑定事件的元素 
* @param type : 事件名称。不加 "on". 如 : "click" 而不是 "onclick". 
* @param fn : 事件处理函数 
************************************/
function bind(obj, type, fn) {
if (obj.attachEvent) {
obj['e' + type + fn] = fn;
obj[type + fn] = function () { obj['e' + type + fn](window.event); }
obj.attachEvent('on' + type, obj[type + fn]);
} else
obj.addEventListener(type, fn, false);
}

【Related Recommended】

1. Free js online video tutorial

2. JavaScript Chinese Reference Manual

3. php.cn Dugu Jiujian (3) - JavaScript video tutorial

The above is the detailed content of Detailed introduction to the use tutorial of ZeroClipboard. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn