//mixin函数

基础使用方法

--包含选择器,example:
.test(){
&:hover{
border:1px solid red;
}
} button{
.test;
} //output css
button:hover {
border: 1px solid red;
} --命名空间,example:
.test(){
.Height{
height:80px;
}
} //grammar 1
.study{
.test>.Height;
} //grammar 2
.study{
.test > .Height;
} //grammer 3
.study{
.test .Height;
} //grammar 4
.study{
.test.Height;
} //output css
.study {
height: 80px;
} 小结:你可以在mixin函数中定义多个函数,并可以用以上4种任意方法去调用,他们之间的空格和>都是可选的
可有的类似于JavaScript中的方法对象,区别在于他的调用没有那么严谨,example:
#outer > .inner;
#outer > .inner();
#outer .inner;
#outer .inner();
#outer.inner;
#outer.inner();
全部都是可以成功调用#outer mixin函数中的.inner函数--(此处来自文档) --保护命名空间,example: @mianColor:red; //grammar 1
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
} //output css
#test .childColor {
border: 1px solid blue;
} //grammar 2
#test when(@mianColor=red){
.childColor(){
border:1px solid blue;
}
.study{
.childColor;
}
} //output css
#test .study {
border: 1px solid blue;
} 当这个时候.childColor函数无论是立即执行还是指定条件执行在#test外部都是无法调用的,这样起到命名空间保护
这里的 when(@mianColor=red)起到了当在指定条件为true是才会执行
注意:@mianColor的声明必须在外部才会起到作用,example:
when true
//grammar 1
@mianColor:red;
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
} //grammar 2
@mianColor:blue;
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
}
@mianColor:red; when false
//grammar 1
@mianColor:blue;
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
} //grammar 2
@mianColor:red;
#test when(@mianColor=red){
.childColor{
border:1px solid blue;
}
}
@mianColor:blue; //error grammar 1
@mianColor:red;
#test when(@mianColor=red){
@mianColor:blue;
.childColor{
border:1px solid blue;
}
}
这样的最终结果还是为真 //error grammar 2
@mianColor:blue;
#test when(@mianColor=red){
@mianColor:red;
.childColor{
border:1px solid blue;
}
}
这样的最终结果还是为假 小结:内部不会改变外部声明变量,同时外部也不能调取内部函数,这其实和JavaScript函数的闭包是一个道理

作者:leona

原文链接:http://www.cnblogs.com/leona-d/p/6296580.html

版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接

Less-mixin函数基础二的更多相关文章

  1. python 18 函数基础二

    转自 http://www.cnblogs.com/BeginMan/p/3173328.html 一.装饰器(decorators) 装饰器的语法以@开头,接着是装饰器函数的名字.可选参数. 紧跟装 ...

  2. 函数基础(二)(day11整理)

    目录 昨日内容 函数的定义 函数的三种定义方式 空函数 有参函数 无参函数 函数的调用 函数的返回值 函数的参数 形参 实参 今日内容 可变长参数 可变长形参 可变长实参(仅作了解) 函数对象 函数嵌 ...

  3. PHP基础入门(二)【PHP函数基础】

    PHP基础入门(二)--函数基础 了解 PHP基础入门详解(一) 后,给大家分享一下PHP的函数基础. 这部分主要讲的就是: 函数的声明与使用.PHP中变量的作用域.静态变量.函数的参数传递.变量函数 ...

  4. LR函数基础(一)(二)

    LR函数基础(一) 函数用到:web_reg_find(). lr_log_message(). lr_eval_string().strcmp().atoi() Action(){    web_r ...

  5. Ruby语法基础(二)

    Ruby语法基础(二) 继续ruby的学习,这次主要把目光放到运算符,条件判断,循环,方法,以及其他ruby特有的基本概念上 运算符 算术运算符:+,-,/,%,**,值的注意的是,ruby中一切皆为 ...

  6. jdbc基础 (二) 通过properties配置文件连接数据库

    csdn博文地址:jdbc基础 (二) 通过properties配置文件连接数据库 上一篇描述了对mysql数据库的简单操作,下面来看一下开发中应该如何灵活应用. 因为jdbc对数据库的驱动加载.连接 ...

  7. Python 函数基础、有序集合、文件操作(三)

    一.set 特点: set是一个无序且不重复的元素集合访问速度快:天生解决元素重复问题 方法: 初始化 >>> s1 = set()>>> print(type(s ...

  8. 【2017-03-05】函数基础、函数四种结构、ref和out参数、递归

    一.函数基础 1.函数/方法:非常抽象独立完成某项功能的一个个体 2.函数的作用: 提高代码的重用性提高功能开发的效率提高程序代码的可维护性 3.分类 固定功能函数高度抽象函数 4.函数四要素:输入, ...

  9. PHP基础入门(三)---PHP函数基础

    PHP基础入门(三)---函数 今天来给大家分享一下PHP的函数基础.有了前两章的了解,想必大家对PHP有了一定的基础了解.想回顾前两章的朋友可以点击"PHP基础入门(一)"&qu ...

随机推荐

  1. STL容器分析--list

    就是一双向链表,可高效地进行插入删除元素.

  2. 要练习的lambda

    取list的id 放入新List<Integer> List<Integer> list1 = list.stream().map(albumGroup1 -> albu ...

  3. Atitit.执行cmd 命令行 php

    Atitit.执行cmd 命令行 php 1. 执行cmd 命令行,调用系统命令的基础 1 1.1. 实际执行模式 1 1.2. 空格的问题 1 1.3. 中文路径的问题,程序文件读取编码设置 1 1 ...

  4. VS编译duilib项目时候的错误解决方法整理

    @1:找不到Riched20.lib 用everything等软件搜索下磁盘.找到所在的文件夹加入到vs的库文件夹就可以.我得是C:\Program Files (x86)\Microsoft SDK ...

  5. springboot+springAOP实现数据库读写分离及数据库同步(MySQL)----最新可用2019-2-14

    原文:https://blog.csdn.net/wsbgmofo/article/details/79260896 1,数据源配置文件,如下 datasource.readSize=1spring. ...

  6. jks & pfk

    keytool and jks keytool Name keytool - Key and Certificate Management Tool Manages a keystore (datab ...

  7. O(1)取Queue中的最大值

    实现原理: 1.利用Stack的先进后出的特性,实现一个MaxStack,MaxStack中用一个Stack记录当前的值,一个Stack记录当前的最大值. 2.用2个MaxStack实现MaxQueu ...

  8. js 阻止事件冒泡 支持所有主流浏览器

    function getEvent(){ if(window.event) {return window.event;} func=getEvent.caller; while(func!=null) ...

  9. ubuntu16.0.4 update git

    Ubuntu 16.04 comes with Git 2.7.x, which is a little old now. As versions 2.8 & 2.9 are not part ...

  10. tomcat修改默认端口

    1.webserver: tomcat2.version:   Apache Tomcat/7.0.293.operation: 修改默认端口 3.1 修改tomcat目录下的/conf/server ...