H5移动web页面触摸按钮效果实现-模拟按钮hover效果实现
2016-02-14 16:52
771 查看
移动端触摸按钮的效果,可明示用户有些事情正要发生,是一个比较好体验,但是移动设备中并没有鼠标指针,使用css的hover并不能满足我们的需求,还好国外有个激活css的active效果,代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
<style>
.btn{
display: block;
position: relative;
top: 100px;
margin: 20px;
width: 200px;
height: 50px;
line-height: 50px;
text-align: center;
border-radius: 5px;
font-size: 18px;
color: salmon;
background-color: skyblue;
}
.btn-on{
background-color: slateblue;
}
</style>
</head>
<body>
<div class="btn"></div>
<script>
var btn=document.querySelector(".btn");
btn.ontouchstart=function(){
this.className="btn btn-on";
}
btn.ontouchend=function(){
this.className="btn";
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
<style>
.btn{
display: block;
position: relative;
top: 100px;
margin: 20px;
width: 200px;
height: 50px;
line-height: 50px;
text-align: center;
border-radius: 5px;
font-size: 18px;
color: salmon;
background-color: skyblue;
}
.btn-on{
background-color: slateblue;
}
</style>
</head>
<body>
<div class="btn"></div>
<script>
var btn=document.querySelector(".btn");
btn.ontouchstart=function(){
this.className="btn btn-on";
}
btn.ontouchend=function(){
this.className="btn";
}
</script>
</body>
</html>
相关文章推荐
- HTML5进入全屏和退出全屏
- html5
- html5 学习资料
- HTML5のFile&FileSystem
- html5 css3 颜色表示和透明度设置
- html5 css3 配色表
- H5拖曳文件上传示例
- H5的拖曳效果示例
- HTML5のWeb Worker
- HTML5开发实战——Sencha Touch篇(2)
- html5全屏
- HTML5开发实战——Sencha Touch篇(1)
- html5原生canvas内image旋转
- HTML5开发移动web应用——Sencha Touch篇(12)
- html5 旋转 canvas
- html5 画笔(brush)
- html5 太阳系(2)
- html5 太阳系(1)
- html5 form表单
- html5 时钟