Skip to content

Instantly share code, notes, and snippets.

View nicholasxjy's full-sized avatar
🤞
AFK

xue nicholasxjy

🤞
AFK
View GitHub Profile
// 屏幕可视窗口大小
window.innerHeight // 标准浏览器及IE9+
document.documentElement.clientHeight // 标准浏览器及低版本IE标准模式
document.body.clientHeight // 低版本混杂模式
// 浏览器窗口顶部与文档顶部之间的距离,也就是滚动条滚动的距离
window.pagYOffset // 标准浏览器及IE9+
document.documentElement.scrollTop // 兼容ie低版本的标准模式
document.body.scrollTop // 兼容混杂模式
@nicholasxjy
nicholasxjy / toblob.js
Created November 14, 2017 07:20
base 64 to blob
export function b64toBlob(data, contentType = '', sliceSize = 512) {
const byteCharacters = atob(data)
const byteArrays = []
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize)
const byteNumbers = new Array(slice.length)
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i)
}
const byteArray = new Uint8Array(byteNumbers)
[
{
"name": {
"en": {
"official": "Republic of Albania",
"common": "Albania"
},
"zh": {
"official": "阿尔巴尼亚共和国",
"common": "阿尔巴尼亚"
[
{
"name": {
"en": {
"official": "Republic of Albania",
"common": "Albania"
},
"zh": {
"official": "阿尔巴尼亚共和国",
"common": "阿尔巴尼亚"
@nicholasxjy
nicholasxjy / titleCase.js
Created May 9, 2017 03:32
titlecase string in js
function titleCase(str) {
str = str.toLowerCase()
return str.charAt(0).toUpperCase() + str.slice(1)
}
<link rel="icon" type="image/png" href="./src/favicon.png">
@nicholasxjy
nicholasxjy / numWithCommas.js
Created March 1, 2017 02:31
format number with commas
export function numberWithCommas(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
@nicholasxjy
nicholasxjy / formatTime.js
Created March 1, 2017 02:29
generic format time
function parseTime(time, format = 'y-m-d h:i:s') {
if (!time) {
return '0000-00-00 00:00:00'
}
const date = time instanceof Date ? time : new Date(parseInt(time, 10))
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,