julytian / issues-blog Goto Github PK
View Code? Open in Web Editor NEW记录学习前端知识
License: MIT License
记录学习前端知识
License: MIT License
px转rem
@function px2em($px, $base-font-size: 20px) {
@if (unitless($px)) {
@warn "Assuming #{$px} to be in pixels, attempting to convert it into pixels for you";
@return px2em($px + 0px); // That may fail.
} @else if (unit($px) == rem) {
@return $px;
}
@return ($px / $base-font-size) * 1rem;
}
opacity
@mixin opacity($opacity:50) {
opacity: $opacity / 100;
filter: alpha(opacity=$opacity);
}
box-shadow
@mixin box-shadow($shadow...) {
-webkit-box-shadow:$shadow;
box-shadow:$shadow;
}
text省略符
@mixin text-overflow() {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/julytian/test.git
git push -u origin master
git remote add origin https://github.com/julytian/test.git
git push -u origin master
npm install -g rimraf
cd xxx[include node_modules folder] rimraf node_modules
--转自饿了么
在 Web 开发中,经常要对表单元素的输入进行限制,比如说不允许输入特殊字符,标点。通常我们会监听 input 事件:
inputElement.addEventListener('input', function(event) {
let regex = /[^1-9a-zA-Z]/g;
event.target.value = event.target.value.replace(regex, '');
event.returnValue = false
});
这段代码在 Android 上是没有问题的,但是在 iOS 中,input 事件会截断非直接输入,什么是非直接输入呢,在我们输入汉字的时候,比如说「喜茶」,中间过程中会输入拼音,每次输入一个字母都会触发 input 事件,然而在没有点选候选字或者点击「选定」按钮前,都属于非直接输入。
这显然不是我们想要的结果,我们希望在直接输入之后才触发 input 事件,这就需要引出我要说的两个事件—— compositionstart
和compositionend
。
compositionstart
事件在用户开始进行非直接输入的时候触发,而在非直接输入结束,也即用户点选候选词或者点击「选定」按钮之后,会触发 compositionend
事件。
var inputLock = false;
function do(inputElement) {
var regex = /[^1-9a-zA-Z]/g;
inputElement.value = inputElement.value.replace(regex, '');
}
inputElement.addEventListener('compositionstart', function() {
inputLock = true;
});
inputElement.addEventListener('compositionend', function(event) {
inputLock = false;
do(event.target);
})
inputElement.addEventListener('input', function(event) {
if (!inputLock) {
do(event.target);
event.returnValue = false;
}
});
添加一个 inputLock 变量,当用户未完成直接输入前,inputLock 为 true,不触发 input 事件中的逻辑,当用户完成有效输入之后,inputLock 设置为 false,触发 input 事件的逻辑。这里需要注意的一点是,compositionend 事件是在 input 事件后触发的,所以在 compositionend事件触发时,也要调用 input 事件处理逻辑。
@charset "utf-8";
/* reset */
html{
-webkit-text-size-adjust:none;
-webkit-user-select:none;
-webkit-touch-callout: none
font-family: Helvetica;
}
body{font-size:12px;}
body,h1,h2,h3,h4,h5,h6,p,dl,dd,ul,ol,pre,form,input,textarea,th,td,select{margin:0; padding:0; font-weight: normal;text-indent: 0;}
a,button,input,textarea,select{ background: none; -webkit-tap-highlight-color:rgba(255,0,0,0); outline:none; -webkit-appearance:none;}
em{font-style:normal}
li{list-style:none}
a{text-decoration:none;}
img{border:none; vertical-align:top;}
table{border-collapse:collapse;}
textarea{ resize:none; overflow:auto;}
/* end reset */
/* public */
/* 清除浮动 */
.clear { zoom:1; }
.clear:after { content:''; display:block; clear:both; }
/* 定义盒模型为怪异和模型(宽高不受边框影响) */
.boxSiz{
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box;
}
/* 强制换行 */
.toWrap{
word-break: break-all; /* 只对英文起作用,以字母作为换行依据。 */
word-wrap: break-word; /* 只对英文起作用,以单词作为换行依据。*/
white-space: pre-wrap; /* 只对中文起作用,强制换行。*/
}
/* 禁止换行 */
.noWrap{
white-space:nowrap;
}
/* 禁止换行,超出省略号 */
.noWrapEllipsis{
white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
/* 文字两端对齐 */
.text-justify{
text-align:justify;
text-justify:inter-ideograph;
}
/* 定义盒模型为 flex布局兼容写法并让内容水平垂直居中 */
.flex-center{
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -o-box;
display: box;
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-o-box-pack: center;
box-pack: center;
-webkit-box-align: center;
-moz-box-align: center;
-ms-flex-align: center;
-o-box-align: center;
box-align: center;
}
/* public end */
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<meta content="email=no" name="format-detection">
<title>title</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
content...
</body>
</html>
1. 禁止ios和android用户选中文字
.css{-webkit-user-select:none}
2、禁止ios长按时触发系统的菜单,禁止ios&android长按时下载图片
.css{-webkit-touch-callout: none}
3、webkit去除表单元素的默认样式
.css{-webkit-appearance:none;}
4、修改webkit表单输入框placeholder的样式
input::-webkit-input-placeholder{color:#AAAAAA;}
input:focus::-webkit-input-placeholder{color:#EEEEEE;}
5、去除android a/button/input标签被点击时产生的边框 & 去除ios a标签被点击时产生的半透明灰色背景
a,button,input{-webkit-tap-highlight-color:rgba(255,0,0,0);}
6、ios使用-webkit-text-size-adjust禁止调整字体大小
body{-webkit-text-size-adjust: 100%!important;}
7、android 上去掉语音输入按钮
input::-webkit-input-speech-button {display: none}
8、移动端定义字体,移动端没有微软雅黑字体
/* 移动端定义字体的代码 */
body{font-family:Helvetica;}
9、禁用Webkit内核浏览器的文字大小调整功能。
-webkit-text-size-adjust: none;
1、手机拍照和上传图片
<!-- 选择照片 -->
<input type=file accept="image/*">
<!-- 选择视频 -->
<input type=file accept="video/*">
2、取消input在ios下,输入的时候英文首字母的默认大写
<input autocapitalize="off" autocorrect="off" />
3、打电话和发短信
<a href="tel:0755-10086">打电话给:0755-10086</a>
<a href="sms:10086">发短信给: 10086</a>
FastClick 是 FT Labs 专门为解决移动端浏览器 300 毫秒点击延迟问题所开发的一个轻量级的库
electron_mirror=https://cdn.npm.taobao.org/dist/electron/
目前对提升移动端CSS3动画体验的主要方法有几点:
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
如动画过程有闪烁(通常发生在动画开始的时候),可以尝试下面的Hack:
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-perspective: 1000;
-moz-perspective: 1000;
-ms-perspective: 1000;
perspective: 1000;
box-shadows
与gradients
往往都是页面的性能杀手,尤其是在一个元素同时都使用了它们,所以拥抱扁平化设计吧。
使用于频繁操作,例如 resize, scroll 等操作
function throttle(method,delay,duration){
var timer=null, begin=new Date();
return function(){
var context=this, args=arguments, current=new Date();;
clearTimeout(timer);
if(current-begin>=duration){
method.apply(context,args);
begin=current;
}else{
timer=setTimeout(function(){
method.apply(context,args);
},delay);
}
}
}
每次我们判断间隔了多久,要是超过设置时间则立即执行一次
引用
详情
不兼容ie6、ie7.
npm :
npm config set registry http://registry.npm.taobao.org
yarn :
yarn config set registry http://registry.npm.taobao.org
只指定node-sass的下载源:
npm:
npm config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
yarn:
yarn config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
后我可以正常使用npm或者yarn进行下载了~
移动端一般会把头部,尾部固定不滚动,传统用法:position:fixed
。但是在一些低版本浏览器,例如:QQ浏览器就不支持这个写法。解决方法,使用 position:absolute
。
记住滚动条是html身上的,所以需要隐藏滚动条。
html {
width:100%;
height: 100%;
overflow: hidden;
}
body{
width:100%;
height: 100%;
overflow: auto;
}
function proMove() {
var agent = navigator.userAgent.toLowerCase(); //检测是否是ios
var iLastTouch = null; //缓存上一次tap的时间
if(agent.indexOf('iphone') >= 0 || agent.indexOf('ipad') >= 0) {
document.body.addEventListener('touchend', function(event) {
var iNow = new Date().getTime();
iLastTouch = iLastTouch || iNow + 1 /** 第一次时将iLastTouch设为当前时间+1 */ ;
var delta = iNow - iLastTouch;
if(delta < 500 && delta > 0) {
event.preventDefault();
return false;
}
iLastTouch = iNow;
}, false);
}
}
# 全局安装webpack,webpack-dev-server
$ npm install -g webpack
$ npm install -g webpack-dev-server
# 为项目安装其他依赖
$ npm i webpack-merge css-loader style-loader file-loader url-loader babel-core babel-loader babel-plugin-transform-runtime babel-preset-es2015 babel-preset-stage-0 babel-runtime vue-loader vue-html-loader vue-style-loader vue-hot-reload-api -D
webpack-merge:开发环境和生产环节的webpaak配置文件的配置合并
css-loader:编译写入css
style-loader:把编译后的css整合进html
file-loader:编译写入文件,默认情况下生成文件的文件名是文件名与MD5哈希值的组合
vue-laoder:编译写入.vue文件
vue-html-loader:编译vue的template部分
vue-style-loader:编译vue的样式部分
vue-hot-reload-api:webpack对vue实现热替换
babel-core:ES2015编译核心
babel-loader:编译写入ES2015文档
babel-preset-es2015:ES2015语法
babel-preset-stage-0:开启测试功能
babel-runtime:babel执行环境
如果想把css单独分离出来,使用 extract text plugin for webpack
在命令行中运行如下安装:
npm i lib-flexible --save
在项目入口文件 main.js 里 引入 lib-flexible
// main.js
import 'lib-flexible'
在项目根目录的 index.html 中添加如下 meta
<meta name="viewport" content="width=device-width, initial-scale=1.0">
实际开发中,我们通过设计稿得到的值单位是 px,所以要将 px 转换成 rem 再写进样式中。
将 px 转换成 rem 我们将使用 px2rem 这个工具,它有 webpack 的 loader:px2rem-loader
在 CSS 中 pointer-events: none
可以使得鼠标穿透该层,点击到下方元素。
伪元素中使用 content: attr(data-*)
可插入自定义属性中的内容。
单行文字长度自适应,超出长度显示省略号:
.class {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
有时当我们写完一个H5的表单页面,在浏览器手机模式测好,以为完事的时候,结果还是会收到用户提交的bug,页面出错了!!!
用户在手机上点击输入框,键盘弹出,使页面高度改变,导致页面布局错误。(部分手机型号)
$(document).ready(function () {
$('body').height($('body')[0].clientHeight);
});
当手机软键盘弹出时,有些型号的手机(IOS没问题,部分Android有)的屏幕会被键盘占去一部分,导致页面高度改变。上面的代码是在页面加载完毕后,将body的高度设置成设备屏幕的高度,这样即使键盘弹出,页面的高度也不会改变。
在window 下执行 npm i gulp-sass --save-dev
安装 gulp-sass
时一直出错。
查找答案发现如下解决方法:
先安装 ruby ,因为sass 依赖ruby
在安装的时候,请勾选 Add Ruby executables to your PATH 这个选项,添加环境变量,不然以后使用编译软件的时候会提示找不到ruby环境。
执行ruby -v
,有结果表示成功
安装sass,这时受国内网络被墙,需要修改 安装源:
gem sources —remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l
gem install sass
最后在你的目录下执行npm i gulp-sass --save-dev
就安装成功了
new TimeLineMax()
参数说明:
(1)元素选择器或对象
(2)持续时间
(3)对象 变化的属性——>值
(4)【可选】动画延迟发生时间 可写数字, " -=0.5 " , " +=0.5 "
解释说明:当add()里面的参数是一个函数的时候,添加函数并执行函数
add()配合tweenTo()使用,当完成某一个状态之前的动画时,添加add(function(){}),执行次函数。
当TweenTo()里面的参数是时间的时候,即为完成指定时间内的动画。
参数说明:(1)指定时间或状态 (2)【可选】布尔值 true:不执行函数 默认; false:执行函数
参数说明:(1)元素选择器或对象(2)持续时间 (3)对象 变化的属性——>值 (4)【可选】动画延迟发生时间 可写数字, '-=0.5','+=0.5'
其中前三个参数和to()类似,重点说明一下第四个参数
参数说明:1、状态的字符串 返回值是一个数字
解释说明:getLabelTime()和currentLable()结合使用
获取当前状态开始到结束所使用的时间,demo见以下
参数说明:1、时间数字 返回值是状态的字符串,如果没有下一个状态返回null
参数说明:1、时间数字 返回值是状态的字符串,如果没有上一个状态返回null
Tween类型:
Linear Quadratic Cubic Quartic Quintic Sinusoidal Exponential Circular Elastic Back Bounce
ease类型:
easeIn easeOut easeInOut
<div class="loading">
<div class="inner"> <i class="before"></i> <i class="after"></i> </div>
<div class="text">
<span class="pace-progress"></span> <br>加载中...
</div>
</div>
.loading {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: 9999;
background-color: #363535
}
.loading .inner {
display: block;
position: absolute;
left: 50%;
top: 50%;
width: 5.33333rem;
height: 5.33333rem;
margin: -2.66667rem 0 0 -2.66667rem;
border-radius: 50%;
border: .08rem solid transparent;
border-top-color: #3498db;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite
}
.loading .inner .before {
position: absolute;
top: .13333rem;
left: .13333rem;
right: .13333rem;
bottom: .13333rem;
border-radius: 50%;
border: .08rem solid transparent;
border-top-color: #e74c3c;
-webkit-animation: spin 3s linear infinite;
animation: spin 3s linear infinite
}
.loading .inner .after {
position: absolute;
top: .4rem;
left: .4rem;
right: .4rem;
bottom: .4rem;
border-radius: 50%;
border: .08rem solid transparent;
border-top-color: #f9c922;
-webkit-animation: spin 1.5s linear infinite;
animation: spin 1.5s linear infinite
}
.loading .text {
width: 3.66667rem;
position: absolute;
left: 48%;
top: 48%;
margin: -.8rem 0 0 -1.33333rem;
line-height: 1.6rem;
font-size: .8rem;
text-align: center;
color: #eadcdb
}
@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg)
}
to {
-webkit-transform: rotate(1turn);
transform: rotate(1turn)
}
}
@keyframes spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg)
}
to {
-webkit-transform: rotate(1turn);
transform: rotate(1turn)
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.