scss SCSS mixin支持所有iOS Safari版本的vh和vw单元。基于Patrick Burtchaell的想法:https://gist.github.com/pburtcha
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scss SCSS mixin支持所有iOS Safari版本的vh和vw单元。基于Patrick Burtchaell的想法:https://gist.github.com/pburtcha相关的知识,希望对你有一定的参考价值。
/**
* Fix for vw, vh, vmin, vmax on iOS 7.
* http://caniuse.com/#feat=viewport-units
*
* This fix works by replacing viewport units with px values on known screen sizes.
*
* iPhone 6 and 6 Plus cannot run iOS 7, so are not targeted by this fix.
* Target devices running iOS 8+ will incidentally execute the media query,
* but this will still produce the expected result; so this is not a problem.
*
* As an example, replace:
*
* height: 50vh;
* font-size: 5vmin;
*
* with:
*
* @include viewport-unit(height, 50vh);
* @include viewport-unit(font-size, 5vmin);
*/
@mixin viewport-unit($property, $value) {
#{$property}: $value;
$unit: unit($value);
@if (index((vw, vh, vmin, vmax), $unit) != null) {
$devices: (
(768px, 1024px), // iPad (all versions)
(320px, 480px), // iPhone 4
(320px, 568px) // iPhone 5, 5C, 5S
);
@each $device in $devices {
$device-width: nth($device, 1);
$device-height: nth($device, 2);
$device-query: "only screen and (-webkit-min-device-pixel-ratio: 1)";
$device-query: "#{$device-query} and (device-width: #{$device-width})";
$device-query: "#{$device-query} and (device-height: #{$device-height})";
$percent: $value / ($value * 0 + 1); // see https://github.com/sass/sass/issues/533
$percent-width: $device-width * $percent / 100;
$percent-height: $device-height * $percent / 100;
@if ($unit == vmin or $unit == vmax) {
@media #{$device-query} {
#{$property}: if($unit == vmin, $percent-width, $percent-height);
}
}
@else {
@media #{$device-query} and (orientation: portrait) {
#{$property}: if($unit == vw, $percent-width, $percent-height);
}
@media #{$device-query} and (orientation: landscape) {
#{$property}: if($unit == vw, $percent-height, $percent-width);
}
}
}
}
}
以上是关于scss SCSS mixin支持所有iOS Safari版本的vh和vw单元。基于Patrick Burtchaell的想法:https://gist.github.com/pburtcha的主要内容,如果未能解决你的问题,请参考以下文章
scss Mixins使用flexbox进行跨浏览器支持
scss Linear-Gradient SCSS Mixin使用供应商前缀快速轻松地创建背景渐变,以获得最大的浏览器支持。
scss 灰度和棕褐色滤镜SASS mixin(支持SVG滤镜)
scss 灰度和棕褐色滤镜SASS mixin(支持SVG滤镜)
附加到 SCSS @mixin 的奇怪字符
text 简单但有效,Opacity SCSS Mixin将应用供应商前缀以改进浏览器支持。