sass - Retinal屏border显示1px

@mixin border($top, $right, $bottom, $left, $color:#f00) {
content: " ";
position: absolute;
top: $top;
right: $right;
bottom: $bottom;
left: $left;
color: $color;
$position: '';
$transform-origin: '';
$scale: '';
@if $top == 'auto' or $bottom == 'auto' {
height: 1px;
$scale: 1, .5;
}
@else if $left == 'auto' or $right == 'auto' {
width: 1px;
$scale: .5, 1;
}
@if $top == 'auto' {
$position: bottom;
$transform-origin: 0 100%;
}
@else if $right == 'auto' {
$position: left;
$transform-origin: 0 0;
}
@else if $bottom == 'auto' {
$position: top;
$transform-origin: 0 0;
}
@else if $left == 'auto' {
$position: right;
$transform-origin: 100% 0;
}
border-#{$position} : 1px solid $color;
-webkit-transform-origin: $transform-origin;
transform-origin: $transform-origin;
-webkit-transform: scale($scale);
transform: scale($scale);
z-index: 1;
}
.demo {
position: relative;
&:before {
@include border(0, 0, auto, 0, #666); // top, right, bottom, left, color
}
}

Javascript、Jquery获取浏览器和屏幕各种高度宽度

Javascript:

document.body.clientWidth        //网页可见区域宽(body)
document.body.clientHeight //网页可见区域高(body)
document.body.offsetWidth //网页可见区域宽(body),包括border、margin等
document.body.offsetHeight //网页可见区域宽(body),包括border、margin等
document.body.scrollWidth //网页正文全文宽,包括有滚动条时的未见区域
document.body.scrollHeight //网页正文全文高,包括有滚动条时的未见区域
document.body.scrollTop //网页被卷去的Top(滚动条)
document.body.scrollLeft //网页被卷去的Left(滚动条)
window.screenTop //浏览器距离Top
window.screenLeft //浏览器距离Left
window.screen.height //屏幕分辨率的高
window.screen.width //屏幕分辨率的宽
window.screen.availHeight //屏幕可用工作区的高
window.screen.availWidth //屏幕可用工作区的宽

Jquery:

$(window).height()                 //浏览器当前窗口可视区域高度
$(document).height() //浏览器当前窗口文档的高度
$(document.body).height() //浏览器当前窗口文档body的高度
$(document.body).outerHeight(true) //浏览器当前窗口文档body的总高度 包括border padding margin
$(window).width() //浏览器当前窗口可视区域宽度
$(document).width() //浏览器当前窗口文档对象宽度
$(document.body).width() //浏览器当前窗口文档body的宽度
$(document.body).outerWidth(true) //浏览器当前窗口文档body的总宽度 包括border padding margin

gulpfile.js

gulpfile.js放置在根目录下,
启动命令’gulp serve’

// 组件
gulp
browser-sync // 自动刷新

Read more

base.css

常用的base.css初始化样式


@charset "UTF-8";
* {
margin: 0;
padding: 0;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-tap-highlight-color: transparent;
}

html, body {
color: #333;
background: #fff;
line-height: 1.2;
}

a {
color: #D7171F;
}

a:hover {
color: #D7171F;
text-decoration: none;
}

html {
-webkit-font-smoothing: antialiased;
}

body,
button,
input,
select,
textarea {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}

button,
input,
select {
vertical-align: middle;
outline: none;
}

textarea {
outline: none;
resize: none;
}

input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
color: #b3b3b3;
}

input:-moz-placeholder,
textarea:-moz-placeholder {
color: #b3b3b3;
}

input::-moz-placeholder,
textarea::-moz-placeholder {
color: #b3b3b3;
}

input:-ms-input-placeholder,
textarea:-ms-input-placeholder {
color: #b3b3b3;
}

/*::-webkit-scrollbar{width:5px;}
::-webkit-scrollbar-track{background-color:#fff;}
::-webkit-scrollbar-thumb{background-color:#ccc; border-radius:4px;}
::-webkit-scrollbar-thumb:hover {background-color:#ccc}
::-webkit-scrollbar-thumb:active {background-color:#ccc}*/

table {
border-collapse: collapse;
border-spacing: 0;
}

img {
border: 0;
}

ol,
ul {
list-style: none;
}

.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}

retinajs使用摘要

官方文档:retinajs

注:需要准备的图片名称格式

image.png
image@2x.png
image@3x.png

现在有4种实现方式:

  1. 自动交换“img”标签的”src”路径。
  2. 在内联样式中自动交换背景图像的网址。
  3. 手动指定一个高分辨率的图像不同位置。
  4. 自动创建CSS背景图像媒体查询。
Read more

Retina屏幕下border 1px解决方案

retinal屏幕下@2x, @3x会使css设定好的border 1px变成2倍或者3倍。
以@2x为例,用css解决这个放大的问题(此方法能解决直线)

.scale{
position: relative;
}
.scale:after{
content: '';
position: absolute;
bottom: 0;
left: 0;
right: 0;
border-bottom: 1px solid #ddd;
-webkit-transform: scaleY(.5);
-webkit-transform-origin: 0 0;
}

jQuery插件的基本格式写法

(function($) {

// funName 是控件名称
$.fn.funName = function(options) {

// 设置默认值
var defaults = {
choose: 'red',
out: '#000'
}

// 如果options有的话就用options,或者使用default参数
var options = $.extend(defaults, options);

// 遍历 return 链式操作
return this.each(function() { // 这里的this是jQuery对象

var $this = $(this); // 这里的this是当前循环的dom

// 例当前dom和同级其它dom分别添加颜色属性
$this.css('color', options.choose).siblings().css('color', options.out);

});

}

})(jQuery);

$(function() {
// 调用
$('#demo').funName({'choose':'green', 'out':'#f00'});
});

SASS用法指南

一、什么是SASS

SASS是一种CSS的开发工具,提供了许多便利的写法,大大节省了设计者的时间,使得CSS的开发,变得简单和可维护。

二、安装和使用

2.1 安装

SASS是Ruby语言写的,但是两者的语法没有关系。不懂Ruby,照样使用。只是必须先安装Ruby,然后再安装SASS。

假定你已经安装好了Ruby,接着在命令行输入下面的命令:

gem install sass

然后,就可以使用了。

Read more

fastclick.js插件使用简单说明

资源下载:fastclick.js

为什么存在延迟?

从点击屏幕上的元素到触发元素的 click 事件,移动浏览器会有大约 300 毫秒的等待时间。为什么这么设计呢? 因为它想看看你是不是要进行双击(double tap)操作。

引入插件步骤

1.在HTML页面中添加

<script type='application/javascript' src='/path/to/fastclick.js'></script>

注:必须在页面所有Element之前加载脚本文件先实例化fastclick

2.在JS中添加fastclick的身体,推荐以下做法:

if ('addEventListener' in document) {  
document.addEventListener('DOMContentLoaded', function() {
FastClick.attach(document.body);
}, false);
}

如果你使用了JQuery,那么JS引入就可以改用下面的写法:

$(function() {  
FastClick.attach(document.body);
});

如果你使用Browserify或者其他CommonJS-style 系统,当你调用require('fastclick')时,FastClick.attach事件会被返回,加载FastClick最简单的方式就是下面的方法了:

var attachFastClick = require('fastclick');  
attachFastClick(document.body);

php发出http(post,get)请求

web service model很多时候需要使用别的web service来建造自己的web service,这就需要到使用服务器端进行请求http操作,post或者get请求。

/**
* PHP发送请求获取数据
* @param [type] $url [description]
* @param [type] $post_data [description]
* @return [type] $result [description]
*/
function send_post($url, $post_data) {
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',//or GET
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}

以上是发送请求的函数,具体操作如下:

//使用方法
$post_data = array(
'username' => 'stclair2201',
'password' => 'handan'
);
$result=send_post('http://localhost/ServiceProvider/index.php/Index/getService', $post_data);