• 技术文章 >php教程 >PHP开发

    兼容主流浏览器的css渐变色

    2016-06-07 17:23:34原创683
    有的时候,为了实现一些特殊效果,需要将页面元素某块区域设置成渐变色,一般来说都是通过ps图片方法来实现,但是图片放得多了会影响网页的打开速度,本文介绍的就是用纯 CSS 实现 IE 、Firefox、Chrome 和 和Safari都支持的渐变色效果。


    支持IE的css渐变色设置

    FILTER: progid:DXImageTransform.Microsoft.gradient(GradientType=1,startColorstr='#EEEEEE', endColorstr='#ffffff');


    GradientType=0:垂直渐变, GradientType=1:默认值,水平渐变。


    支持Firefox的css渐变色设置

    background:-moz-linear-gradient(top, #EEEEEE, #ffffff);/*Firefox*/

    top:表示由上到下渐变,其它参数可以是left、right、bottom

    支持Safari、Chrome的css渐变色设置

    background:-webkit-gradient(linear, 0 0, 0 bottom, from(#EEEEEE), to(#ffffff));/*Safari 、Chrome*/

    如果要兼容多种浏览器,把上面的几种综合起来,看下面例子

    ");
    };
    
    //check document ready
    function docReady(t) {
        "complete" === document.readyState ||
        "interactive" === document.readyState
          ? setTimeout(t, 1)
          : document.addEventListener("DOMContentLoaded", t);
    }
    
    //check if wwads' fire function was blocked after document is ready with 3s timeout (waiting the ad loading)
    docReady(function () {
      setTimeout(function () {
        if( window._AdBlockInit === undefined ){
            ABDetected();
        }
      }, 3000);
    });