Home > Web Front-end > JS Tutorial > body text

Detailed introduction to the use tutorial of ZeroClipboard

零下一度
Release: 2017-05-11 13:37:32
Original
2447 people have browsed it

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

<script src="../Assets/js/jquery-1.8.3.min.js"></script>
<script src="../Assets/js/ZeroClipboard/ZeroClipboard.js"></script>
Copy after login

3. Initialize plug-in

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

clip.setHandCursor(true);
clip.addEventListener(&#39;onmouseup&#39;, function (client) { //创建监听 
 // 可以在这儿写一个方法处理相应的事件逻辑
 clip.setText(&#39;要复制到剪切板中的内容&#39;); 
});
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[&#39;e&#39; + type + fn] = fn;
obj[type + fn] = function () { obj[&#39;e&#39; + type + fn](window.event); }
obj.attachEvent(&#39;on&#39; + type, obj[type + fn]);
} else
obj.addEventListener(type, fn, false);
}
Copy after login

【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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template