杂货铺

作者: 你若像风 | 来源:发表于2019-04-12 16:36 被阅读0次

1、css修改input、textarea标签placeholder属性默认文字颜色

    input::-webkit-input-placeholder {
        color: #9e9e9e;
    }
    input:-moz-placeholder {
        color: #9e9e9e;
    }
    input::-moz-placeholder {
        color: #9e9e9e;
    }
    input::-ms-input-placeholder {
        color: #9e9e9e;
    }

2、正则判断是否为手机号

isPoneAvailable (pone) {
    var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
     if (!myreg.test(pone)) {
         return false;
     } else {
         return true;
    }
}

3、获取页面url参数

function getQuery(key) {
    let query = location.href.split('?')[1]
    if(!query) {
        return
    }
    query = query.split('&')
    for(let i in query) {
        let q = query[i].split('=')
        if(q[0] == key) {
            return q[1]
        }
    }
}

4、解决移动端滑动穿透

export function setHtmlScroll(v, flag) {
    if(flag) {
        v.curPos = document.documentElement.scrollTop || document.body.scrollTop;
        document.querySelector('html').style.position = 'fixed';
        document.querySelector('html').style.top = -v.curPos + 'px';
    }
    if(!flag) {
        document.querySelector('html').style.position = 'static';
        document.querySelector('html').style.top = 'auto';
        window.scrollTo(0, v.curPos);
    }
}

export default {
    data() {
        return {
            curPos: 0,
        };
    },
}

5、正则表达式校验只能输入数字、保留两位小数、不可为0、不可为负

//取数字
newVal = newVal.replace(/[^\d.]/g,"");
//保证只有出现一个.而没有多个.
newVal = newVal.replace(/\.{2,}/g,".");
//必须保证第一个为数字而不是.
newVal = newVal.replace(/^\./g,"");
//保证.只出现一次,而不能出现两次以上
newVal = newVal.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
//只能输入两个小数
newVal = newVal.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');

6、element-ui datePicker 设置当前日期之前的日期不可选

<template>
    <el-date-picker
      v-model="value2"
      align="right"
      type="date"
      placeholder="选择日期"
      :picker-options="pickerOptions1">
    </el-date-picker>
</template>
 
 
<script>
  export default {
    data() {
      return {
        pickerOptions1: {
         disabledDate(time) {
            return time.getTime() < Date.now() - 8.64e7;
          },
        }       
      }
    }
  }

7、设置当前日期之后的日期不可选

disabledDate(time) {
    return time.getTime() > Date.now();
}

8、弹出数字键盘

<!-- 有"#" "*"符号输入 -->
<input type="tel">

<!-- 纯数字 -->
<input pattern="\d*">

9、用系统的某些功能

<!-- 拨号 -->
<a href="tel:10086">打电话给: 10086</a>

<!-- 发送短信 -->
<a href="sms:10086">发短信给: 10086</a>

<!-- 发送邮件 -->
<a href="mailto:839626987@qq.com">发邮件给:839626987@qq.com</a>

<!-- 选择照片或者拍摄照片 -->
<input type="file" accept="image/*">

<!-- 选择视频或者拍摄视频 -->
<input type="file" accept="video/*">

<!-- 多选 -->
<input type="file" multiple>

10、打开原生应用

<a href="weixin://">打开微信</a>
<a href="alipays://">打开支付宝</a>
<a href="alipays://platformapi/startapp?saId=10000007">打开支付宝的扫一扫功能</a>
<a href="alipays://platformapi/startapp?appId=60000002">打开支付宝的蚂蚁森林</a>

11、忽略自动识别

<!-- 忽略浏览器自动识别数字为电话号码 -->
<meta name="format-detection" content="telephone=no">

<!-- 忽略浏览器自动识别邮箱账号 -->
<meta name="format-detection" content="email=no">

12、解决input失焦后页面没有回弹

<template>
  <input type="text" @focus="focus" @blur="blur">
</template>

<script>
  export default {
    data() {
      return {
        scrollTop: 0
      }
    },
    methods: {
      focus() {
        this.scrollTop = document.scrollingElement.scrollTop;
      },
      blur() {
        document.scrollingElement.scrollTo(0, this.scrollTop);
      }
    }
  }
</script>

13、禁止长按

// 禁止长按图片保存
img {
  -webkit-touch-callout: none;
  pointer-events: none; // 像微信浏览器还是无法禁止,加上这行样式即可
}

// 禁止长按选择文字
div {
  -webkit-user-select: none;
}

// 禁止长按呼出菜单
div {
  -webkit-touch-callout: none;
}

14、滑动不顺畅,粘手

一般出现在IOS设备中,自定义盒子使用了overflow: auto || scroll后出现的情况。
div {
  -webkit-overflow-scrolling: touch;
}

15、屏幕旋转为横屏时,字体大小会变

* {
  -webkit-text-size-adjust: 100%;
}

16、最简单的rem自适应

// 初始化
html {
 font-size: calc(100vw / 3.75); 
}
// 子元素使用
body {
  font-size: .14rem;
}

17、滑动穿透

当在遮罩上滑动的时候,是会穿透到父节点的,最简单的办法就是阻住默认行为:

<div class="mask">
  <div class="content">我是弹框</div>
</div>
.mask {
  position: fixed;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: rgba($color: #333, $alpha: .6);

  .content {
    padding: 20px;
    background-color: #fff;
    width: 300px;
  }
}
document.querySelector(".mask").addEventListener("touchmove", event => {
  event.preventDefault();
});

如果在vue中,你可以这么写:

<div class="mask" @touchumove.prevent></div>
如果.content也有滚动条,那么只要阻止遮罩本身就行:

document.querySelector(".mask").addEventListener("touchmove", event => {
  if (event.target.classList.contains("mask")) event.preventDefault();
});

或者:

<div class="mask" @touchumove.self.prevent></div>

这样,当出现遮罩的时候用户的滑动就会被锁住啦👌

相关文章

  • 这是一个杂货铺的仓库

    我有一个杂货铺, 这里是杂货铺的仓库。 杂货铺已经很杂七杂八, 杂货铺的仓库, 就更不用提了。 不过,我不在乎, ...

  • 杂货铺的故事

    杂货铺之所以叫“杂货铺” ,是因为里面不仅有小吃,还有各种各样的摆放齐全的货物。 杂货铺的老板...

  • 体育西竟藏着一家小店,什么都能交换,包括你的前任...

    《解忧杂货铺》中说,现代人内心流失的东西,书里的“杂货铺”可以帮你找回。 而在广州竟然真有一家现实版的解忧杂货铺,...

  • 一剂良药——读《解忧杂货铺》有感

    读完《解忧杂货铺》,我认为,咨询者遇到了困境,选择愿意相信杂货铺,不是真正为了排忧解难,而是一种情感宣泄。杂货铺的...

  • 2018书单

    今日读完解忧杂货铺

  • 解忧杂货铺

    从名字的字面意思上我们就可以看出来,主语是杂货铺,状语是解忧。是一家杂货铺,什么样的杂货铺呢?用于解忧。 在这部分...

  • NO.冰淇淋

    苦咖啡和巧乐多,你爱哪一个? NO.冰淇淋是一家杂货铺,叫这样的名字,是因为杂货铺的冰柜里有远远多于其他杂货铺的冰...

  • 杂货铺的猫

    想要把一个便利店说成杂货铺,或者想象成一个杂货铺,觉得那样会别有一番韵味,杂货铺里面会有更多的生活气息,有年代感和...

  • 亲爱的,让我爱你(1)

    郑宝宝第一次看见白然是在学校门口的杂货铺。 校门口的这个杂货铺在附近这几所大学内都颇有人气,因为在这个小杂货铺你想...

  • 我的简书《解忧杂货铺》

    我的简书《解忧杂货铺》:

网友评论

      本文标题:杂货铺

      本文链接:https://www.haomeiwen.com/subject/srocwqtx.html