Skip to content

Instantly share code, notes, and snippets.

View ntnyq's full-sized avatar
🐣
Learning rust

ntnyq ntnyq

🐣
Learning rust
View GitHub Profile
@ntnyq
ntnyq / passive-event.md
Created July 31, 2019 15:22
[Passive event warning] #JavaScript

滑动时页面警告

[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive.

解决方法

* {
@ntnyq
ntnyq / netease-outer-player.md
Created July 31, 2019 14:58
[Netease music outer player] #API

Outer chain link player

<iframe
  src="https://music.163.com/outchain/player?type=2&id=27896818&auto=1&height=66" 
  frameborder="0" 
  border="1"
  marginwidth="0" 
 marginheight="0"
@ntnyq
ntnyq / globalThis.js
Last active July 26, 2019 14:08
get Global This
function getGlobalThis () {
if (typeof self !== 'undefined') return self
if (typeof window !== 'undefined') return window
if (typeof global !== 'undefined') return global
// This may still return wrong result ⚠️
if (typeof this !== 'undefined') return this
throw new Error('Unable to local global `this`')
}
@ntnyq
ntnyq / anime.css
Last active July 2, 2019 00:51
Common css animation
.msg {
animation: animeMsg 4.5s ease-in-out infinite;
}
@keyframes animeMsg {
0% {
opacity: 0;
}
50% {
@ntnyq
ntnyq / img-preload.js
Created June 19, 2019 02:58
Preload images with promise
const loadImg = (img) => {
const isArray = Array.isArray(img)
if (!isArray) {
const oImg = new Image()
oImg.src = img
return new Promise(resolve => {
oImg.onload = () => {
resolve()
}
})
@ntnyq
ntnyq / getImageSize.ts
Created May 31, 2019 06:37
Get the size of img HTMLElement
export function getImageSize (img: HTMLElement) {
const p = new Promise((resolve, reject) => {
if (img.natutralWidth) {
resolve({ width: img.naturalWidth, height: img.naturalHeight })
}
const image = new Image()
image.onload = () => {
resolve({ width: image.width, height: image.height })
@ntnyq
ntnyq / Auth-check-if-app.js
Last active September 6, 2019 09:53
[Vue utils] #Utils #Vue
new Vue({
data () {
return {
authSuccess: false
};
},
methods: {
goLogin () {
window.location.href = './login.html';
}
@ntnyq
ntnyq / raf.js
Created March 1, 2019 17:13
raf-fallback-to-setTimeout
let lastTime = 0
const prefixes = 'webkit moz ms o'.split(' ') // 各浏览器前缀
let requestAnimationFrame
let cancelAnimationFrame
const isServer = typeof window === 'undefined'
if (isServer) {
requestAnimationFrame = function() {
return
@ntnyq
ntnyq / fix-ios-scroll-top.js
Created January 25, 2019 10:40
修复移动端软键盘弹起,导致页面滚动后无法回滚的问题。
(function (doc, win) {
var body = doc.body;
var hasScrollTopChange = false; // 连续点击Input
var lastScrollTop = body.scrollTop; // 获取软键盘唤起时浏览器滚动部分的高度
var scrollTimer = null;
$('input[type="text"], input[type="tel"], input[type="number"], input[type="password"], textarea')
.focus(function () {
// 获取焦点时触发
clearInterval(scrollTimer);
@ntnyq
ntnyq / download_file.js
Last active September 6, 2019 09:56
[Download file] #JavaScript
// simulate click event
const blob = new Blob([ '' ], { type: 'application/octet-stream' })
const url = window.URL.createObjectURL(blob)
const save_link = document.createElement('a')
save_link.href = 'path_to_your_file/url' //
save_link.download = '[filename].[ext]'
const event = document.createEvent('MouseEvents')
event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
save_link.dispatchEvent(event)
window.URL.revokeObjectURL(url)