Skip to content

Instantly share code, notes, and snippets.

// 自动滚动
// 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() {
@luobotang
luobotang / Image_Drag_Preview.html
Created August 23, 2017 06:51
Image_Drag_Preview
<!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; }
@luobotang
luobotang / dispatchCustomEvent.js
Created August 23, 2017 08:22
DispatchCustomEvent
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');
@luobotang
luobotang / scrollElementIntoView
Created October 25, 2017 10:38
将元素移动到屏幕可见范围内
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
}
@luobotang
luobotang / pageshow-demo.html
Last active May 3, 2018 08:02
pageshow demo
<!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 / cmd-text-format.js
Created November 15, 2017 08:56
控制台文本格式化工具
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() {
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 / babel.config.js
Created February 20, 2019 08:37
DEMO - Error of assign to read only 'exports' of object - caused by webpack and @babel/preset-env with special config
module.exports = {
presets: [
[
'@babel/env',
{
useBuiltIns: 'usage',
modules: false
}
]
]