Some wrapper functions

js```

//解析URL
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){
var ret = {},
seg = a.search.replace(/^?/,'').split('&'),
len = seg.length, i = 0, s;
for (;i<len;i++) {
if (!seg[i]) { continue; }
s = seg[i].split('=');
ret[s[0]] = s[1];
}
return ret;
})(),
file: (a.pathname.match(//([^\/?#]+)$/i) || [,''])[1],
hash: a.hash.replace('#',''),
path: a.pathname.replace(/^([^\/])/,'/$1'),
relative: (a.href.match(/tps?://[^\/]+(.+)/) || [,''])[1],
segments: a.pathname.replace(/^//,'').split('/')
};
}

// 对象复制
function cloneObjectFn (obj){
return JSON.parse(JSON.stringify(obj))
}
跑马灯
function fontRound(btnId) {
var linkTag = G(btnId + ' .font');
var textLen = strLen(linkTag.innerText);
var text = linkTag.innerText + '  '
$$.removeClass(btnId + ' .font', "ellipsis");

// console.log(textLen)
if (textLen > 18) {
linkTag.innerHTML = text;
}
var myTimer = setInterval(
function() {
if (linkTag) {
var text = linkTag.innerText;
if (textLen <= 18) return;
var newText = text.substr(1) + text.charAt(0);
console.log(newText);
linkTag.innerHTML = newText;
}

    }, 500
);

return myTimer;

}
```

Guess you like

Origin www.cnblogs.com/hyx626/p/11781076.html