不使用 JavaScript,仅在 CSS 中实现为 IE10 / IE11 单独设置样式(IE11 不支持 flex: 1; / ES6,IE11 之前不支持 Swiper)

目录

1. 为 IE10 / IE11 单独设置样式(exp:文字渐变色)

2. IE11 不支持 flex: 1(exp:行政办公)

3. IE11 中 不可以使用 es6(exp:防抖定时器)

4. IE11 之前的版本不兼容 swiper


1. 为 IE10 / IE11 单独设置样式(exp:文字渐变色)

  • 文字渐变色 为例,IE10 / IE11 不支持 该属性
  • 为提高用户体验,除了设置主流浏览器的样式外,还应针对 IE10 / IE11 进行单独设置
  • 在 css 中采用 媒体查询 可以实现上述需求
    <style>
      .top {
        color: transparent;
        background-image: linear-gradient(0deg, red, blue);
        -webkit-background-clip: text;
        font-size: 60px;
      }

      @media screen and(-ms-high-contrast: active), (-ms-high-contrast: none) {
        .top {
          color: red;
          background: none;
        }
      }
    </style>

    <div class="top"> IE11 不兼容文字渐变 </div>
  • IE10 / IE11 效果:
  • Chrome 效果:

2. IE11 不支持 flex: 1(exp:行政办公)

  •  如果采用 flex 布局:
  • 必须指定子元素 宽度 或者 高度,让子元素分配父容器 
  • 子元素不能写 flex: 1,这不能使其自动平分剩余空间 
  • IE11 之前版本的 IE浏览器,对 flex布局 支持很差

3. IE11 中 不可以使用 es6(exp:防抖定时器)

  • 发现这个问题是因为,我当时再写弹框划出的事件,在 chrome 中正常,在 IE11 中无效
  • 报错的位置是 防抖函数:function delayFun()
  • 该函数的主要作用:防止短时间内多次点击弹框触发按钮,导致弹框动画效果失效
 function delayFun(fn) {
    let timeout = null;
    return function () {
      clearTimeout(timeout);
      timeout = setTimeout(() => {
        fn.apply(this, arguments);
      }, 100);
    };

  $(".model-handle").click(
    delayFun(function () {
      $(this).parent("li").addClass("active").siblings().removeClass("active");
      modalIndex = $(this).attr("data-modalHandleIndex");
      eachMyModal(modalIndex);
    })
  );
  • 这里报错是因为,IE11 不能识别 es6 语法,setTimeout 后面跟了 es6 语法
  • 解决方案:去语法转换网站,将 es6 转换为 es5
  1. babel 在线转换地址:Babel · The compiler for next generation JavaScript (babeljs.io)
  2. Traceur 在线转换地址:Traceur (google.github.io)
  • 注意:直接将 setTimeout 后面改成 function 无效,还是直接转换比较安全
  function delayFun(fn) {
    var timeout = null;
    return function () {
      var _this = this,
        _arguments = arguments;

      clearTimeout(timeout);
      timeout = setTimeout(function () {
        fn.apply(_this, _arguments);
      }, 100);
    };
  }

4. IE11 之前的版本不兼容 swiper

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lyrelion

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值