mixin.scss

//-----------------------------------浏览器前缀-----------------------------------------
//例子:@include css3(transition, 0.5s);
@mixin css3($property, $value) {
@each $prefix in -webkit-,
-moz-,
-ms-,
-o-,
'' {
#{$prefix}#{$property}: $value;
}
} //-----------------------------------Retina图片-----------------------------------------
@mixin image-2x($image, $width, $height) {
@media (min--moz-device-pixel-ratio: 1.3), (-o-min-device-pixel-ratio: 2.6/2), (-webkit-min-device-pixel-ratio: 1.3), (min-device-pixel-ratio: 1.3), (min-resolution: 1.3dppx) {
/* on retina, use image that's scaled by 2 */
background-image: url($image);
background-size: $width $height;
}
} //-----------------------------------清除浮动-----------------------------------------
//引用例子:@include clearfix();
@mixin clearfix() {
&:before,
&:after {
content: "";
display: table;
}
&:after {
clear: both;
}
} //-----------------------------------Black和White-----------------------------------------
//特别声明,上面这个不属于Sass的Mixins范畴,是Sass的自定义函数功能。
//background:black(0.15);
//color:white(0.9);}
@function black($opacity) {
@return rgba(0, 0, 0, $opacity)
} @function white($opacity) {
@return rgba(255, 255, 255, $opacity)
} //-----------------------------------内阴影和外阴影-----------------------------------------
//引用例子:@include box-emboss(0.8, 0.05);
@mixin box-emboss($opacity, $opacity2) {
box-shadow: white($opacity) 0 1px 0, inset black($opacity2) 0 1px 0;
} //-----------------------------------行高-----------------------------------------
//引用例子:@include line-height (16);
@mixin line-height($heightValue: 12) {
line-height: $heightValue + px; //fallback for old browsers
line-height: (0.125 * $heightValue) + rem;
} //-----------------------------------隐藏文字-----------------------------------------
//引用例子:
//.logo{
// background: url("logo.png");
// height:100px;
// width:200px;
// @include hide-text;
//}
@mixin hide-text {
overflow: hidden;
text-indent: -9000px;
display: block;
} //-----------------------------------响应式断点-----------------------------------------
//引用例子:
//@include breakpoint(large) {
// width: 60%;
//}
//@include breakpoint(medium) {
// width: 80%;
//}
//@include breakpoint(small) {
// width: 95%;
//}
@mixin breakpoint($point) {
@if $point==large {
@media (min-width: 64.375em) {
@content;
}
}
@else if $point==medium {
@media (min-width: 50em) {
@content;
}
}
@else if $point==small {
@media (min-width: 37.5em) {
@content;
}
}
} //-----------------------------------正三角-----------------------------------------
//正三角的通用属性
%triangleBase {
_font-size: 0;
_line-height: 0;
_overflow: hidden;
width: 0;
height: 0; } //regulaTriangle:正三角(dashed默认透明)
//例子:@include regulaTriangle(top,red);
@mixin regulaTriangle($derection:bottom, $color: #000, $width: 20px) {
@extend %triangleBase;
border-width: $width;
//向右
@if $derection==right {
border-style: dashed dashed dashed solid;
border-color: transparent transparent transparent $color;
}
//向左
@if $derection==left {
border-style: dashed solid dashed dashed;
border-color: transparent $color transparent transparent;
}
//向上
@if $derection==top {
border-style: dashed dashed solid dashed;
border-color: transparent transparent $color transparent;
}
//向下
@if $derection==bottom {
border-style: solid dashed dashed dashed;
border-color: $color transparent transparent transparent;
}
} //-----------------------------------直角三角形-----------------------------------------
//right-angledTriangle:直角三角形
//例子:@include right-angledTriangle(1,red);
@mixin right-angledTriangle ($derection:1, $color:#000, $width: 20px, $opacity:transparent, $border:dashed) {
@extend %triangleBase;
border-width: $width;
//向右
@if $derection==1 {
border-style: $border dashed dashed $border;
border-color: $color $opacity $opacity $color;
}
//向右
@if $derection==2 {
border-style: $border $border dashed dashed;
border-color: $color $color $opacity $opacity;
}
//向右
@if $derection==3 {
border-style: dashed $border $border dashed;
border-color: $opacity $color $color $opacity;
}
//向右
@if $derection==4 {
border-style: dashed dashed $border $border;
border-color: $opacity $opacity $color $color;
}
} //-----------------------------------圆角-----------------------------------------
//radius:圆角
//例子:@include radius(24,100%);
@mixin radius($num:1234, $size: 5px) {
@if $num==1234 {
-webkit-border-radius: $size; //Saf3+, Chrome
-moz-border-radius: $size; //FF1+
border-radius: $size; //Opera 10.5, IE 9
-ms-border-radius: $size;
}
@if $num==12 {
-webkit-border-top-left-radius: $size;
border-top-left-radius: $size;
-webkit-border-top-right-radius: $size;
border-top-right-radius: $size;
-moz-border-top-left-radius: $size;
-ms-border-top-left-radius: $size;
-moz-border-top-right-radius: $size;
-ms-border-top-right-radius: $size;
}
@if $num==23 {
-webkit-border-top-right-radius: $size;
border-top-right-radius: $size;
-webkit-border-bottom-right-radius: $size;
border-bottom-right-radius: $size;
-moz-border-top-right-radius: $size;
-moz-border-bottom-right-radius: $size;
-ms-border-top-right-radius: $size;
-ms-border-bottom-right-radius: $size;
}
@if $num==34 {
-webkit-border-bottom-right-radius: $size;
border-bottom-right-radius: $size;
-webkit-border-bottom-left-radius: $size;
border-bottom-left-radius: $size;
-moz-border-bottom-left-radius: $size;
-moz-border-bottom-right-radius: $size;
-ms-border-bottom-left-radius: $size;
-ms-border-bottom-right-radius: $size;
}
@if $num==14 {
-webkit-border-top-left-radius: $size;
border-top-left-radius: $size;
-webkit-border-bottom-left-radius: $size;
border-bottom-left-radius: $size;
-moz-border-top-left-radius: $size;
-moz-border-bottom-left-radius: $size;
-ms-border-top-left-radius: $size;
-ms-border-bottom-left-radius: $size;
}
@if $num==13 {
-webkit-border-top-left-radius: $size;
-webkit-border-bottom-right-radius: $size;
-ms-border-top-left-radius: $size;
-ms-border-bottom-right-radius: $size;
border-top-left-radiu: $size;
-moz-border-top-left-radius: $size;
border-bottom-right-radiu: $size;
-moz-border-bottom-right-radius: $size;
}
@if $num==24 {
-webkit-border-top-right-radius: $size;
border-top-right-radius: $size;
-webkit-border-bottom-left-radius: $size;
border-bottom-left-radius: $size;
-moz-border-top-right-radius: $size;
-moz-border-bottom-left-radius: $size;
-ms-border-top-right-radius: $size;
-ms-border-bottom-left-radius: $size;
}
} //-----------------------------------边框阴影-----------------------------------------
//boxshadow:边框阴影
//例子:@include boxshadow(24,100%);
@mixin boxshadow($x: 3px, $y: 3px, $shadowcolor: #cccccc) {
-moz-box-shadow: $x $y 4px $shadowcolor; // FF3.5+
-webkit-box-shadow: $x $y 4px $shadowcolor; // Saf3.0+, Chrome
box-shadow: $x $y 4px $shadowcolor; // Opera 10.5, IE 9.0
filter: progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$shadowcolor}');
/* IE6,IE7 */
-ms-filter: "progid:DXImageTransform.Microsoft.dropshadow(OffX=#{$x}, OffY=#{$y}, Color='#{$shadowcolor}')";
/* IE8 */
} //-----------------------------------透明度-----------------------------------------
//myOpacity:透明度
//例子:@include myOpacity(0.3,93,197,16);
@mixin myOpacity($opacity:0.5, $r:0, $g:0, $b:0) {
$xx: $opacity * 100;
filter: alpha(opacity=$xx);
background-color: rgba($r, $g, $b, $opacity); // rgba()和opacity都能实现透明效果,但最大的不同是opacity作用于元素,以及元素内的所有内容的透明度,而rgba()只作用于元素的颜色或其背景色.两种都不被IE支持(IE9开始支持)
//如果要兼容ie文字不透明,需要用元素把文字包裹起来,然后色值position:relative或者absolute。
//opacity: $opacity;//opacity属性是css3的属性,也可以实现透明效果,跟background-color: rgba同样效果。
}
//-----------------------------------透明度-----------------------------------------
//引用例子:@include opacity(0.8);
@mixin opacity($opacity) {
opacity: $opacity;
$opacity-ie: $opacity * 100;
filter: alpha(opacity=$opacity-ie); //IE8
}
//-----------------------------------动画keyframes生成-----------------------------------------
//动画keyframes生成
//例子:@include keyframes(动画名称);
//@include keyframes(move-the-object) {
// 0% {
// transform: translateX(0);
// }
// 100% {
// transform: translateX(200px);
// }
//}
@mixin keyframes($animationName) {
@-webkit-keyframes #{$animationName} {
@content;
}
@-moz-keyframes #{$animationName} {
@content;
}
@-o-keyframes #{$animationName} {
@content;
}
@keyframes #{$animationName} {
@content;
}
}

.

mixin的更多相关文章

  1. vue.mixin与vue.extend

    vue.mixin 全局注册一个混合,影响注册之后所有创建的每个 Vue 实例.谨慎使用全局混合对象,因为会影响到每个单独创建的 Vue 实例(包括第三方模板).大多数情况下,只应当应用于自定义选项, ...

  2. 用mixin引入模块后, 方法重名的解析方法

    关于mixin, 经常被问到一个问题是, 方法查找是如何处理的? 特别地, 如果类, 父类, 以及类所包含的mixin中, 都定义有相同名字的方法时, 会发生什么? 答案是, ruby首先会从对象的直 ...

  3. 组件嵌套+Mixin函数demo

    非DOM属性:1.dangerouslysetInnerHTML(xxs跨站攻击) 2.key 3.ref 编写组件嵌套 <!DOCTYPE html><html>  < ...

  4. 从mixin到new和prototype:Javascript原型机制详解

    从mixin到new和prototype:Javascript原型机制详解   这是一篇markdown格式的文章,更好的阅读体验请访问我的github,移动端请访问我的博客 继承是为了实现方法的复用 ...

  5. sass揭秘之@mixin,%,@function

    因为文章内含有很多sass代码,如需自己动手查看编译结果,推荐使用sassmeister这款在线编译工具,方便你阅读学习. 在阅读本文章之前,请先确认你已经阅读了上篇文章sass揭秘之变量,不然会给你 ...

  6. 你的 mixin 兼容 ECMAScript 5 吗

    原文:Are your mixins ECMAScript 5 compatible? 作者:Nicholas C. Zakas 我最近在与客户合作的项目中,需要充分利用的 ECMAScript 5, ...

  7. Design Pattern: Not Just Mixin Pattern

    Brief 从Mix-In模式到Mixin模式,中文常用翻译为“混入/织入模式”.单纯从名字上看不到多少端倪,而通过采用Mixin模式的jQuery.extend我们是否可以认为Mixin模式就是深拷 ...

  8. mixin设计模式

    mixin可以轻松被一个子类或者一组子类继承,目的是函数复用.在js中,我们可以将继承MiXin看作为一种通过扩展收集功能的方式. e.mixin = function(t) { for (var i ...

  9. Ruby学习之mixin

    直接上代码: module Action def jump @distance = rand(4) + 2 puts "I jumped forward #{@distance} feet! ...

  10. 我的常用mixin 之 lines

    /** * 最多显示 $lineCount 行 * lines * * example: * @include lines; * @include lines(3); */ @mixin lines( ...

随机推荐

  1. javascript中Date对象复习

    js的Date对象不怎么经常用,所以忘得差不多,复习一下 1.声明一个Date对象,默认本地当前时间 var date = new Date();//Fri Apr 28 2017 14:26:19 ...

  2. 2017微软 MVP 数据实践技术活动日(北京站)

    Power BI | 交互式数据可视化 BI 工具 EXCEL BI :无所不能的业务数据分析利器 EXCEL +POWERBI=EXCEL BI https://edu.hellobi.com/co ...

  3. linux 内核大牛-谢宝友

    http://blog.chinaunix.net/uid/25845340.html 谢宝友:毕业于四川省税务学校税收专业,现供职于中兴通讯操作系统团队,对操作系统内核有较强的兴趣.专职于操作系统内 ...

  4. linux驱动移植的重要数据结构

    转载:http://www.embeddedlinux.org.cn/html/jishuzixun/201304/14-2538.html 对于嵌入式 Linux 系统来说,有各种体系结构的处理器和 ...

  5. 记录一次apache错误:“child pid 29023 exit signal Segmentation fault (11)”

    目前做了一台公网的测试机,主要是  php 5.3.3 版本,是 browser  --> nginx  --> apache --> php 今天因为想要安装一个商城,要求需要 P ...

  6. 关于Unity中Shader的内置值

    Unity provides a handful of builtin values for your shaders: things like current object's transforma ...

  7. word排版汇总

    1.iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成PDF或rtf 的文档,而且可以将XML.Html文件转化为PDF ...

  8. 玩转kafka

    http://zookeeper.apache.org/releases.html#download http://kafka.apache.org/downloads.html(下载最新 二进制版本 ...

  9. 将MyEclipse项目导入到Eclipse中

    1.请首先确保你的eclipse是javaee版本的,或者已经安装wtp插件 2.然后修改eclipse工程下的.project文件: 3.在<natures></natures&g ...

  10. 【BZOJ】【3653】谈笑风生

    dfs序+可持久化线段树 好吧……是我too naive 这题……$$ans=min(dep[x],k)×(size[x]-1)+\sum_{y在x的子树中,且dis(x,y)<=k}(size ...