Skip to content

Instantly share code, notes, and snippets.

View CodeDreamfy's full-sized avatar
💭
I may be slow to respond.

CodeDreamfy CodeDreamfy

💭
I may be slow to respond.
View GitHub Profile
@CodeDreamfy
CodeDreamfy / validFileAccept.md
Created December 11, 2019 10:48
input-file文件accept类型

Valid Accept Types

<input id="fileSelect" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />  

For CSV files (.csv), use:

<input type="file" accept=".csv" />

For Excel Files 97-2003 (.xls), use:

<script type="text/javascript">
var bForcepc
= fGetQuery("dv") == "pc";
function
fBrowserRedirect(){
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIpad = sUserAgent.match(/ipad/i) ==
"ipad";
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsMidp = sUserAgent.match(/midp/i) == "midp";
<script type="text/javascript">
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")<0){
try{
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
window.location.href="http://shipei.qq.com/index.htm";
}else if(/iPad/i.test(navigator.userAgent)){
}else{
window.location.href="http://shipei.qq.com/simple/s/index/"
}
@CodeDreamfy
CodeDreamfy / reactivity.js
Last active March 29, 2019 09:25
Reactivity原理
/*
* 参考: https://mp.weixin.qq.com/s/X3s4ysLfwclEOXIuKzOK2g
*
*/
// 将对象的所有属性加上get,set监听,并调用dep函数
function observe (obj) {
Object.keys(obj).forEach(key => {
let internalValue = obj[key];
const dep = new Dep();
Object.defineProperty(obj, key, {
@CodeDreamfy
CodeDreamfy / js
Created September 4, 2018 11:08 — forked from hugohu/js
JavaScript获取图片的原始尺寸
//HTML5提供了一个新属性naturalWidth/naturalHeight可以直接获取图片的原始宽高。这两个属性在Firefox/Chrome/Safari/Opera及IE9里已经实现。改造下获取图片尺寸的方法。
//http://www.w3.org/TR/2011/WD-html5-author-20110705/the-img-element.html#dom-img-naturalwidth
//http://www.w3.org/TR/2011/WD-html5-author-20110705/the-img-element.html#dom-img-naturalheight
function getImgNaturalDimensions(img, callback) {
var nWidth, nHeight;
if (img.naturalWidth) {
nWidth = img.naturalWidth;
nHeight = img.naturalHeight;
} else {
@CodeDreamfy
CodeDreamfy / throttle.js
Created August 22, 2018 01:55
节流函数
// 兼容 requestAnimationFrame 与 setTimeout
function _throttle (fn, time) {
let running = false
let isFrame = false
if (!time) isFrame = true
const getCallback = (self, args) => {
return () => {
fn.apply(self, args)
running = false
}
@CodeDreamfy
CodeDreamfy / mobile.css
Last active February 8, 2018 02:36
pc,mobile - reset库
/**
reset.css
author : codedreamfy
*/
html,
body,
p,
ol,
ul,
li,
@CodeDreamfy
CodeDreamfy / vue-router.js
Created February 5, 2018 04:31
页面后退路由重新刷新方法
页面后退路由重新刷新方法
```js
// 第一种
router.beforeEach((to, from, next) => {
if(sessionStorage.getItem("back_url") === to) {
刷新
sessionStorage.setItem("back_url", from)
}else {
sessionStorage.setItem("back_url", from)
}
@CodeDreamfy
CodeDreamfy / xmlhttpRequest.js
Last active January 24, 2018 08:34
ajax使用
var xhrReq = new XMLHttpRequest();
xhrReq.onreadystatechange = function(){
var elm = document.getElementById('link1');
if(xhrReq.status == 200 && xhrReq.readyState == 4) {
elm.href = xhrReq.response.payload.apk_url;
}
}
xhrReq.open('get',url);
xhrReq.responseType = 'json';
xhrReq.send();
@CodeDreamfy
CodeDreamfy / dynamic-load.js
Created January 22, 2018 03:44
动态加载css/js
function loadJs(file){
var scriptTag = document.getElementById('loadScript');
var head = document.getElementsByTagName('head').item(0);
if(scriptTag) head.removeChild(scriptTag);
script = document.createElement('script');
script.src = "../js/mi_"+file+".js";
script.type = 'text/javascript';
script.id = 'loadScript';
head.appendChild(script);
}