Skip to content

Instantly share code, notes, and snippets.

View Calerme's full-sized avatar
🏠
Working from home

Caler Loo Calerme

🏠
Working from home
View GitHub Profile
@Calerme
Calerme / index.js
Created October 19, 2018 06:14
禁止 scrollbar 拖动
document.addEventListener('scroll', function (e) {
e.preventDefault();
e.stopPropagation();
document.documentElement.scrollTop = 0;
});
@Calerme
Calerme / String.prototype.padStart
Last active June 29, 2018 02:09
String.prototype.padStart Polyfill
(function () {
String.prototype.padStart = String.prototype.padStart || function padStart (targetLength, content) {
content = String(content)
if (this.length >= targetLength) {
return this
}
var needLength = targetLength - this.length;
var needStr = content;
@Calerme
Calerme / bind polyfill
Created May 16, 2018 07:53
Function.prototype.bind polyfill
(function () {
function _bind(context) {
var fn = this;
var _this = context;
var bindArgs = Array.prototype.slice.call(arguments, 1);
return function () {
var args = Array.prototype.slice.call(arguments);
args = bindArgs.concat(args);
return fn.apply(_this, args);
}
@Calerme
Calerme / 使用 clipboard.js 库.js
Created February 28, 2018 03:42
JavaScript  复制内容到剪贴板
/* 使用 clipboard.js 库 */
@Calerme
Calerme / 动态创建命名空间
Created February 27, 2018 09:40
动态创建命名空间
var MyApp = {};
MyApp.namespace = function (name) {
var parts = name.split('.');
var current = MyApp;
for (var i in parts) {
if ( !current[ parts[i] ] ) {
current[ parts[i] ] = {};
}
current = current[ parts[i] ];
//HTML、CSS禁止选择文字,针对IE、FF、Chrome等
<div unselectable="on" style="-moz-user-select:none;-webkit-user-select:none;" onselectstart="return false;">
你选不了我,
unselectable: IE/Opera,
-moz-user-select: FireFox,
onselectstart: IE/Safari,
-webkit-user-select:Chrome
</div>
@Calerme
Calerme / index.html
Last active March 14, 2018 10:52
使用绝对定位实现宽高自适应&实现绝对定位元素水平垂直居中
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>绝对定位实现自适应与居中</title>
<style>
#box {
position: absolute;
top: 8px;
right: 8px;