Skip to content

Instantly share code, notes, and snippets.

@luobotang
luobotang / babel.config.js
Created Feb 20, 2019
DEMO - Error of assign to read only 'exports' of object - caused by webpack and @babel/preset-env with special config
View babel.config.js
module.exports = {
presets: [
[
'@babel/env',
{
useBuiltIns: 'usage',
modules: false
}
]
]
View get-mysql-db-tables-columns.js
function generateSql(db) {
return `
SELECT
t.table_name,
c.column_name,
c.data_type
FROM
INFORMATION_SCHEMA.TABLES t JOIN
INFORMATION_SCHEMA.COLUMNS c ON
t.table_schema = c.table_schema AND
@luobotang
luobotang / cmd-text-format.js
Created Nov 15, 2017
控制台文本格式化工具
View cmd-text-format.js
var colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
function F(text) {
this.text = text
this.attr = 0
this._color = 0
this._bgColor = 0
}
F.prototype.toString = function() {
View pageshow-demo.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=1, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>BFCache &amp; pageshow</title>
</head>
<body>
<a href="https://www.baidu.com/">leave to baidu.com</a>
@luobotang
luobotang / scrollElementIntoView
Created Oct 25, 2017
将元素移动到屏幕可见范围内
View scrollElementIntoView
function scrollElementIntoView(el, offsetTop) {
var doc = document.documentElement
var docScrollTop = doc.scrollTop || 0
var viewportHeight = window.innerHeight
var rect = el.getBoundingClientRect()
if (rect.top < 0 || rect.top + rect.height > docScrollTop + viewportHeight) {
var elOffsetTop = (rect.top + docScrollTop)
var newScrollTop = elOffsetTop - (offsetTop > 0 ? offsetTop : (rect.height > viewportHeight ? 0 : (viewportHeight - rect.height) / 2))
doc.scrollTop = newScrollTop
}
View dispatchCustomEvent.js
function dispatchCustomEvent(name, data) {
var e;
if (window.CustomEvent) {
e = new window.CustomEvent(name, {
canBubble: true,
cancelable: true,
detail: data
})
} else {
e = document.createEvent('CustomEvent');
View Image_Drag_Preview.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Image Drag Preview</title>
<style>
* { margin: 0; padding: 0; }
#box { padding: 10px; min-height: 500px; background: #f0f0f0; }
View AutoScroll.js
// 自动滚动
// div#demo style:overflow:hidden
// div#demo1
// div#demo2
var SPEED = 60,
demo2 = document.getElementById("demo2"),
demo1 = document.getElementById("demo1"),
demo = document.getElementById("demo");
function Marquee() {