Skip to content

Instantly share code, notes, and snippets.

@jrainlau
jrainlau / signal-interference.css
Last active November 7, 2017 18:53
CSS effect: `signal interference`
.motto-disturb {
position: relative;
}
@keyframes noise-anim {
0% {
clip: rect(55px, 9999px, 9px, 0);
}
5% {
clip: rect(12px, 9999px, 60px, 0);
@jrainlau
jrainlau / throttle.js
Created August 8, 2016 01:47
function throttling
var throttle = function(fn, delay){
var timer = null;
return function(){
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function(){
fn.apply(context, args);
}, delay);
};
};
@jrainlau
jrainlau / ripple-effect.html
Created August 13, 2016 06:33
ripple-effect
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ripple</title>
<style>
.ripple-effect {
position: relative;
background-color: red;
}
@jrainlau
jrainlau / 判断元素是否进入屏幕
Created August 18, 2016 09:34
判断元素是否进入屏幕
ele.getBoundingClientRect().top > window.innerHeight // 元素在当前屏下面
ele.getBoundingClientRect().bottom < 0 // 元素在当前屏上面
@jrainlau
jrainlau / scroll-direction.js
Created August 29, 2016 07:28
滚动方向
var scrollFunc = function (e) {
var direct = 0
e = e || window.event
if (e.wheelDelta) { //判断浏览器IE,谷歌滑轮事件
if (e.wheelDelta > 0) { //当滑轮向上滚动时
console.log("滑轮向上滚动")
}
if (e.wheelDelta < 0) { //当滑轮向下滚动时
console.log("滑轮向下滚动")
}
@jrainlau
jrainlau / ajax.js
Created September 28, 2016 08:08
ajax module
/**
* 发送ajax请求,允许传入一个配置对象和一个回调函数
*
* @param {Object} config 配置对象
* 举例:var config = {
method: 'GET',
url: 'url',
params: {number: 1, price: 10},
async: true
}
@jrainlau
jrainlau / scrollbar.css
Created September 30, 2016 03:03
滚动条样式
*::-webkit-scrollbar {
display: block;
width: 5px;
background: #FAFAFA;
}
*::-webkit-scrollbar-thumb {
border-radius: 5px;
background: #E0E0E0;
}
*::-webkit-scrollbar-thumb:hover {
@jrainlau
jrainlau / copy.js
Created October 12, 2016 03:00
批量复制
const fs = require('fs')
let pic = fs.readFileSync(`${__dirname}/dog.jpg`)
let readStream = fs.createReadStream(`${__dirname}/dog.jpg`)
for (let i = 0; i < 400; i++) {
readStream.pipe(fs.createWriteStream(`${__dirname}/输出目录/dog-${i}.jpg`))
}
@jrainlau
jrainlau / bubble.js
Created March 25, 2017 06:51
bubble canvas background
function rand(min, max) {
return (Math.random() * (max - min)) + min;
}
export default class Bubble {
constructor(canvas) {
this.colors = [
'255, 255, 255'
];
// adds gradient to particles on true
@jrainlau
jrainlau / spider.py
Created January 10, 2018 07:55
小黄文下载爬虫
from bs4 import BeautifulSoup
import requests
import os
def visit_page(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36'
}
r = requests.get(url, headers = headers)