文章目录
HTML5
一.HTML5: 新增了很多语义化标签
<header>:头部标签
<nav>:导航标签
<article>:内容标签
<section>:定义文档某个区域
<aside>:侧边栏标签
<footer>:尾部标签
二.HTML兼容性问题
HTML5兼容性问题:
IE9 行级元素设置宽度的时候 会失效
IE8以下的版本,不支持语义化标签
IE8的内核,无法解析,只能用js替代
解决方案:
<script src="./html5shiv.js"></script>
<script>
// 第一种 通过dom就是手动创建标签
document.createElement("nav")
document.createElement("article")
document.createElement("footer")
// 第二种 就是引入别人写好的一个js文件 html5shiv.js
</script>
三.HTML5对表单的拓展
1.对表单元素的新增:
<body>
<!--
在html5中多了很多东西 其中就有对表单元素的新增
-->
<!-- email -->
邮箱:<input type="email">
<!-- tel -->
电话:<input type="tel">
<!-- url -->
网址:<input type="url">
<!-- number -->
数量:<input type="number" value="0" name="" id="" max="100" min="0">
<!-- color -->
颜色:<input class="color" type="color" name="" id="" >
<!-- 颜色输入框的value 是当前颜色的十六进制 -->
<!-- time -->
时间:<input type="time" name="" id="">
<!-- date -->
日期:<input type="date" name="" id="">
<br>
<!-- datatime -->
日期时间:<input type="datetime" name="" id="">
<!-- 大多数浏览器不支持这个 -->
日期时间:<input type="datetime-local" name="" id="">
</body>
2.对扁担元素的新增:
<body>
<select name="" id="">
<option value="">开封</option>
<option value="">驻马店</option>
<option value="">郑州</option>
</select>
<!-- 建立联系 -->
城市: <input type="text" list="address">
<datalist id="address">
<option value="开封" label="清明上河园">开封</option>
<option value="郑州" label="方特">郑州</option>
<option value="驻马店" label="嵖岈山">驻马店</option>
</datalist>
</body>
3.对表单事件的新增:
<body>
<form action="">
<!--
新增了监听
主要监听内容的改变
-->
电话:<input type="tel" name="" id="tphone" pattern="^1\d{10}$">
<!-- pattern是可以用验证 -->
<!--
1.15286881533
^1\d{11}$
^ 是以什么开头
\d是指数字0-9
{10}就表示 10位
$以什么结尾
正则表达式
-->
<input type="submit">
</form>
</body>
<script>
let tel=document.getElementById("tphone");
// 改变事件 当内容发生改变的时候 就会触发
tel.oninput=function(){
console.log("改变了");
}
// 提交不通过事件
tel.oninvalid=function(){
console.log("提交不通过");
}
</script>
4.进度条:
progress 进度条标签
max 最大值
value 当前进度
<progress max="100" value="60"></progress>
meter 度量器标签
higt 规定当前的较高的值
low 规定当前较低的值
max 最大值
min 最小值
value 当前值
<meter max="100" min="0" high="80" low="40" value="30"></meter>
<!-- 如果我们的当前值在较高值和较低值之外 就会发出黄色的警告 -->
5.HTML5多媒体标签:
对音频的控制:audio
autoplay 如果有这个属性 该音频会立即播放
controls 如果有这个 则会向用户展示控件
loop 如果出现该属性 则表示当音频结束后 会重新开始
muted 当出现这个属性的时候 静音
preload 在页面加载的时候 预备播放 和autoplay冲突
对视频的控制:video
src 视频路径
controls 播放面板
autoplay 自动播放
loop 自动循环
poster 首次进入当前视频的封面图
width
height
CSS3
一.css3就是新增了一些属性
满足各个浏览器的兼容性 我们需要加前缀
<style>
/* 圆角 就是css3中新增的 */
-webkit-border-radius:20px;
/* webkit指的是谷歌的浏览器内核 */
-ms-border-radius:20px;
/* ms指的是ie浏览器的内核 */
-moz-border-radius:20px;
/* moz指的是火狐浏览器的内核 */
-o-border-radius:20px;
/* o指的是opera浏览器的内核 */
</style>
1.透明度:
透明度的表示方式 有三种:
1.rgba(在css3.0中提出的表示颜色的方式,a指的是透明度)
2.opacity(透明度)
3.transparent 表示全透明
rgba的透密和opcity的透明区别
rgba的不会继承,opcity会继承
2.盒子阴影:box-shadow
水平方向上的阴影: box-shadow: 5px 0;
竖直方向上的阴影:box-shadow: 0px 5px;
右下方有阴影 模糊:box-shadow: 5px 5px 20px;
左上方有阴影 模糊:box-shadow: -5px -5px 10px;
右下方有阴影 模糊 红色:box-shadow: 5px 5px 10px 20px red;
内部发光:box-shadow: 5px 5px 10px 20px red inset;
多个阴影:box-shadow:inset 5px 5px 10px 20px red,5px 5px 10px 20px rgb(151, 151, 151);
**3.文字阴影:text-shadow **
text-shadow: 5px 5px 10px blue;
4.背景裁剪:background-clip:
padding-box 把边框下面去掉
content-box 内边距下面 也没有背景
5.背景大小:background-size
6.渐变背景: background-image:linear gradient deg
左往右:background-image: linear-gradient(90deg,red,blue);
下往上: background-image: linear-gradient(0deg,red,blue);
右往左:background-image: linear-gradient(45deg,red,blue);
7.径像渐变: background-image:radial-gradient(100px 100px, red,yellow,pink);
8.多背景:
background: url(…/images/30/ab.png) content-box no-repeat center ,url(…/images/30/xiaoming.jpg) padding-box;
9.插入图片的bug:
<style>
/* 插入图片的时候 两张图片之间会产生一个10px的白边 */
/* 解决方式 把图片转成块级元素 */
/* img{
display: block;
} */
/* 第二种方式 */
img{
vertical-align: middle;
}
</style>
二.CSS3 2D动画
1.transition(参数1,参数2,参数3,参数4)
参数1:发生变化的属性名
参数2:变化的时间(动画时长)
参数3:缓冲曲线
参数4:等待时间
2.贝塞尔曲线
参数3:这个属性可以控制盒子宽度从100px变到400px变化的速度
控制这个速度的变化的过程的算法就叫贝塞尔曲线
特殊值:
linear 匀速动画 cubic-bezier(0,0,1,1)/cubic-bezier(1,1,0,0)
ease-in 先慢后块 cubic-bezier(0.25,0.1,0.25,0.1)
ease-out 先快后慢 cubic-bezier(0,0,0.58,1)
ease-in-out 慢快慢
3.变形:transform
transform: rotate(180deg); //旋转45度 正方向是顺时针的方向
transform: skew(30deg , 30deg); 斜切
div:nth-child(3) img{
transform: scale(0.5);//缩放 /* 负值表示先旋转180° /
transform: translate(30px,30px); //位移
/ 第一个参数表示x轴位移的距离 /
/ 第二个参数表示y轴位移的距离 */
transform: translate(30px,30px) rotate(720deg); //多重变形
三.CSS3 3D动画
1.旋转中心点: transform-origin:
transform-origin: 200px 200px;
2.视距:perspective:
perspective:100px;
3.位移3D:transform: translate3D
右: transform: translate3D(50px,0,0);
下:transform: translate3D(0,50px,0);
右下:transform: translate3D(50px,50px,0);
前:transform: translateZ(50px);
后 :transform: translateZ(-50px);
4.翻面: transform: rotateX(-180deg);
transform: rotateY(-180deg);
transform: rotateZ(-180deg);
5.背面不可见:backface-visibility: hidden;
/* 0-90deg 是可以看到的 90-180是看不到的 */
四.CSS3 自定义动画
1.animation
自定义动画名称
动画时长
缓冲曲线
等待时间
是否停留在终点
播放次数(infinite 表示循环无穷次)
是否交替运动(alternate)
是否暂停(paused)
2.自定义动画 @keyframes就是关键词
<style>
animation: donghua2 3s ease 0s infinite;
@keyframes donghua1{
from{
margin-left: 0px;
}to{
margin-left: 1000px;
}
}
</style>
五.canvas
<body>
<!-- 在这里我定义了一个画布 -->
<canvas width="800" height="500" id="cvs">
您的浏览器不支持canvas
</canvas>
</body>
<script>
window.onload=function(){
// 第一步 得到我们的画布
var cvs=document.getElementById('cvs')
// 第二步 判断你的浏览器是否兼容canvas
if(cvs.getContext){
// 第三步 我们要设置画布类型 得到渲染的上下文
var cvs_context=cvs.getContext('2d')
// 第四步 填充颜色
cvs_context.fillStyle="orange";
// 第五步 绘制
cvs_context.fillRect(200,200,200,200)
// x, y, width, height
cvs_context.fillStyle="rgba(0,0,255,0.5)";
cvs_context.fillRect(100,100,200,200)
}
}
</script>
1.使用canvas绘制图形:
<body>
<canvas id="cvs" width="1800" height="800">
</canvas>
</body>
<script>
window.onload=function(){
let cvs=document.getElementById('cvs');
if(cvs.getContext){
// 绘制矩形
let cvs_context=cvs.getContext("2d");
cvs_context.fillStyle="skyblue";
cvs_context.fillRect(50,0,100,100)
// 绘制边框矩形
cvs_context.strokeStyle="skyblue";
cvs_context.lineWidth=3;
cvs_context.rect(50,150,100,100)
cvs_context.stroke();
// 绘制线
cvs_context.beginPath();//开始划线
cvs_context.moveTo(50,360);//线的起始点
cvs_context.lineTo(100,500);//线的终点
cvs_context.lineWidth=10;
cvs_context.strokeStyle="pink";
cvs_context.stroke();
// 绘制三角形
cvs_context.beginPath();//开始划线
cvs_context.moveTo(400,360);//线的起始点
cvs_context.lineTo(300,500);//线的终点
cvs_context.lineTo(500,500);//线的终点
cvs_context.closePath();//关闭路径
cvs_context.strokeStyle="pink";
cvs_context.fill();
cvs_context.stroke();
// 画弧线
cvs_context.moveTo(250,400);
cvs_context.arc(150,400,100,0,2*Math.PI,false)
// context.arc(x,y,r,sAngle,eAngle,counterclockwise);
cvs_context.stroke();
}
}
</script>
2.颜色渐变
<body>
<canvas></canvas>
</body>
<script>
let canvas=document.querySelector("canvas");
canvas.width=600;
canvas.height=400;
// 获取画笔
let ctx=canvas.getContext("2d");
// 线性渐变 渐变的大小
var gradient = ctx.createLinearGradient(0,0,600,400);
// createLinearGradient (0,0,canvas.width,canvas.height)
// 你要渐变的距离
// 设置颜色
gradient.addColorStop(0,"red");
gradient.addColorStop(0.5,"yellow");
gradient.addColorStop(1,"pink");
// 修改填充样式
ctx.fillStyle=gradient;
// 填充矩形的大小
ctx.fillRect(0,0,600,400)
</script>
3.径向渐变
<body>
<canvas></canvas>
</body>
<script>
var canvas = document.querySelector('canvas');
canvas.width = 600;
canvas.height = 400;
let ctx = canvas.getContext("2d");
// 创建径向渐变
var gradient = ctx.createRadialGradient(300, 200, 20, 300, 200, 200)
// context.createRadialGradient(x0,y0,r0,x1,y1,r1);
/*
x0 渐变的开始圆的 x 坐标
y0 渐变的开始圆的 y 坐标
r0 开始圆的半径
x1 渐变的结束圆的 x 坐标
y1 渐变的结束圆的 y 坐标
r1 结束圆的半径
*/
gradient.addColorStop("0","skyblue")
gradient.addColorStop("0.5","pink")
gradient.addColorStop("1","orange")
// 修改填充样式
ctx.fillStyle=gradient;
ctx.fillRect(0,0,600,400)
</script>
4.文字
<body>
<canvas></canvas>
</body>
<script>
let canvas=document.querySelector("canvas");
canvas.width=600;
canvas.height=400;
let ctx=canvas.getContext("2d");
ctx.beginPath();
ctx.moveTo(100,0);
ctx.lineTo(100,400)
ctx.stroke()
ctx.beginPath();
ctx.moveTo(0,100);
ctx.lineTo(600,100)
ctx.stroke()
// 填充文字的方式 先设置再填充
ctx.font="bold 30px 微软雅黑"
// 充实文字
ctx.fillText("Hello canvas",100,90);
// 镂空文字
ctx.strokeText("Hello canvas",100,150)
</script>
5.阴影
<body>
<canvas></canvas>
</body>
<script>
let canvas=document.querySelector("canvas");
canvas.width=600;
canvas.height=400;
let ctx=canvas.getContext("2d");
var x=-20;
var y=-20;
var blur=0;
setInterval(function(){
ctx.clearRect(0,0,1000,1000)
// 设置阴影
ctx.shadowColor="red";
ctx.shadowOffsetX=x++;
ctx.shadowOffsetY=y++;
ctx.shadowBlur=blur+=0.2;
ctx.fillStyle="yellow"
ctx.fillRect(100,100,200,200)
},100)
</script>
六.弹性布局
给父级加display:flex他的子元素 就会 排排坐
flex布局有一个特征:
当父盒子的高度小于所有子盒子加起来和的高度的话 子级盒子会按照比例进行缩放
当父盒子的宽度小于所有子盒子加起来和的宽度的话 自己盒子会按照比例进行缩放
flex-direction
flex中flex-direction属性
row默认值 横向排布
row-reverse 横向翻转 原本是按照子元素书写顺序从左往右排布 现在反过来了
column纵向排布
column-reverse 纵向反向
flex-wrap:
属性:
nowrap 不换行
wrap 换行
wrap-reverse 翻转换行
**flex-flow 就是flex-direction 和 flex-wrap的结合体
例如:flex-flow: column wrap;
** justify-content:用于处理富余空间
1.flex-start 子元素从主轴开始排布 富余空间在后面
2.flex-end 子元素从主轴开始排布 富余空间在前面
3.center 子元素在中间 富余空间在两边
4.space-between 富余空间在各个子元素中间
5.space-around around周围 富余空间围绕子元素
align-items: :是用来处理元素位置 交叉轴上位置
flex-start 交叉轴上富余空间在后面
flex-end 交叉轴上富余空间在前面
center 子元素在当前行(列)的中间
baseline
stretch 元素被拉伸沾满容器(当高度写死时不适用)
align-content::处理交叉轴富余空间
flex-start 富余空间都在下面
flex-end 富余空间都在上面
center 富余空间都在两边