mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 11:41:20 +08:00
51
ionic/util/feature-detect.ts
Normal file
51
ionic/util/feature-detect.ts
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
export class FeatureDetect {
|
||||
|
||||
run(window, document) {
|
||||
this._results = {};
|
||||
for (let name in featureDetects) {
|
||||
this._results[name] = featureDetects[name](window, document, document.body);
|
||||
}
|
||||
}
|
||||
|
||||
has(featureName) {
|
||||
return !!this._results[featureName];
|
||||
}
|
||||
|
||||
static add(name, fn) {
|
||||
featureDetects[name] = fn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let featureDetects = {};
|
||||
|
||||
|
||||
FeatureDetect.add('positionsticky', function(window, document) {
|
||||
// css position sticky
|
||||
let ele = document.createElement('div');
|
||||
ele.style.cssText = 'position:-webkit-sticky;position:sticky';
|
||||
return ele.style.position.indexOf('sticky') > -1;
|
||||
});
|
||||
|
||||
|
||||
FeatureDetect.add('hairlines', function(window, document, body) {
|
||||
/**
|
||||
* Hairline Shim
|
||||
* Add the "hairline" CSS class name to the body tag
|
||||
* if the browser supports subpixels.
|
||||
*/
|
||||
let canDo = false;
|
||||
if (window.devicePixelRatio >= 2) {
|
||||
var hairlineEle = document.createElement('div');
|
||||
hairlineEle.style.border = '.5px solid transparent';
|
||||
body.appendChild(hairlineEle);
|
||||
|
||||
if (hairlineEle.offsetHeight === 1) {
|
||||
body.classList.add('hairlines');
|
||||
canDo = true;
|
||||
}
|
||||
body.removeChild(hairlineEle);
|
||||
}
|
||||
return canDo;
|
||||
});
|
Reference in New Issue
Block a user