1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
function doCopy($el, {deepCopy = false, copyTips = true, language = "Chinese", bgColor = "#ff6666", fontColor = "#fff"} = {}) {
let tempEl = $("<input id='selectEl' type='text' value=''>").val($el.text())
if (deepCopy) {
tempEl.val($el.html())
}
tempEl.appendTo($("body"))
document.querySelector('#selectEl').select();
document.execCommand('copy');
tempEl.remove()
if (copyTips) {
let tipEl = $("<div class='copyTips' >成功复制到剪切板</div>")
tipEl.css({fontFamily: "'Microsoft YaHei', sans-serif",fontSize: "1.2rem",position: "fixed",top: "1rem",textAlign: "center", left: "50%",fontWeight: "bolder", borderRadius: ".5rem",marginLeft: "-8rem",width: "16rem",height: "3rem", lineHeight:"3rem", background: bgColor,boxShadow: "0 6px 10px -8px #000",color: fontColor, letterSpacing: "4px",boxSizing: "border-box",padding: "0 10px 0 10px", display: "none"})
if (language === "English") {
tipEl.text('Successfully copied!').css({letterSpacing: "0"})
}
tipEl.appendTo($("body"))
$(".copyTips").fadeIn(800)
setTimeout(function () {
$(".copyTips").fadeOut(500)
}, 1000)
}
}
|