Skip to content

Instantly share code, notes, and snippets.

@thinkgarden
thinkgarden / es6.js
Created May 23, 2018 06:24
[js extend] basic js extend method
class Widget {
constructor(width, height, label) {
this.width = width || 50;
this.height = height || 50;
this.$elem = null;
}
render($where){
if(this.$elem) {
this.$elem.css({
@thinkgarden
thinkgarden / utils.js
Last active November 29, 2018 09:38
[js functions] useful function for js #js
// /userinfo/2144/id => ['/userinfo','/useinfo/2144,'/userindo/2144/id']
export function urlToList(url) {
const urllist = url.split('/').filter(i => i);
return urllist.map((urlItem, index) => {
return `/${urllist.slice(0, index + 1).join('/')}`;
});
}
// 极坐标转换成笛卡尔坐标
@thinkgarden
thinkgarden / parallax.js
Last active May 23, 2018 05:35
[parallax] A simple parallax animation plugin for jQuery #mobile #parallax #js
!function($) {
var startPos, // 开始触摸点(X/Y坐标)
endPos,
stage, // 用于标识 onStart/onMove/onEnd 流程的第几阶段,解决 onEnd 重复调用
offset, // 偏移距离
direction, // 翻页方向
curPage, // page 当前页
pageCount, // page 数量
pageWidth, // page 宽度
function arrayToCSV (twoDiArray) {
// Modified from: http://stackoverflow.com/questions/17836273/
// export-javascript-data-to-csv-file-without-server-interaction
var csvRows = [];
// for (var i = 0; i < twoDiArray.length; ++i) {
// for (var j = 0; j < twoDiArray[i].length; ++j) {
// console.log(twoDiArray[i][j])
// temp[i][j] = '\"' + `${dateFns.format(twoDiArray[i][j].timestamp,'HH:mm:ss')}` + '\"'; // Handle elements that contain comma
// }
// csvRows.push(temp[i].join(','));
@thinkgarden
thinkgarden / mvvm.js
Last active May 23, 2018 05:34
[mvvm] A simple code for mvvm framework #js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>forvue</title>
</head>
<body>
<div id="app">
<input type="text" v-model="text"> <br>
{{ text }} <br>
// atomBackup