2013-03-22 64 views
0

我必须使用modernizer来检测浏览器是否支持“cssscrollbar”属性,true或false。基于这个价值,我必须做一些东西,比如添加插件和CSS。Modernizer功能检测

我使用这样的事情下文,这我不知道的:

var frag = document.createDocumentFragment(); 
for (prop in Modernizr) { 
    var para = document.createElement('p'); 
    para.textContent = prop + ': ' + Modernizr[ prop ]; 
    frag.appendChild(para); 
} 

document.body.appendChild(frag); 

检查,我这里指的是fiddle

+1

那么,有什么问题吗? – 2013-03-22 07:27:14

+0

我使用的是2.6.2,它没有得到对cssscrollbar的支持,所以我想为插件添加一个滚动条测试....我是modernizer的新手。 – mandava 2013-03-22 07:28:49

+0

所以你想知道如何测试该功能或如何将测试集成到Modernizr中? – 2013-03-22 07:33:52

回答

0
Modernizr.addTest('cssscrollbar', function() { 

     // Tested Element 
    var test = document.createElement('div'), 

     // Fake body 
     fake = false, 
     root = document.body || (function() { 
      fake = true; 
      return document.documentElement.appendChild(document.createElement('body')); 
     }()), 

     property = 'scrollbar{width:0px;}'; 

    // Force scrollbar 
    test.id = '__sb'; 
    test.style.overflow = 'scroll'; 
    test.style.width = '40px'; 

    // Apply scrollbar style for all vendors 
    test.innerHTML = '&shy;<style>#'+Modernizr._prefixes.join(property+' #__sb::').split('#').slice(1).join('#')+property+'</style>'; 

    root.appendChild(test); 

    // If css scrollbar is supported, than the scrollWidth should not be impacted 
    var ret = test.scrollWidth == 40; 

    // Cleaning 
    document.body.removeChild(test); 
    if (fake) { 
     document.documentElement.removeChild(root); 
    } 
    return ret; 
}); 

如果u添加此则u将会对近代化cssscrollbar支持..................