webapp上的蒙版,包含使用touchstart,touchmove
来源:互联网 发布:appbook for mac 编辑:程序博客网 时间:2024/06/04 18:08
最近很想做一个像美团上点击分类或地址,后面的背景变黑,下拉菜单提亮的效果。如下图
其实做个蒙版很容易拉,这是css的写法。 .mban{position:fixed;z-index:16;top:0;left:0;width:100%;height:100%;background:#000;filter:alpha(opacity=50);-moz-opacity:0.5;opacity:0.5;}
有一点需要注意,就是position:fixed,如果不加入这条,你会发现你的蒙版只是一个屏幕的大小,当你往下活动屏幕时就没有蒙版了。所以就把蒙版固定了,这样滑动屏幕的时候,蒙版还一直显示在页面上。
主要就再看点击的时候显示下拉菜单和蒙版。我是用jQuery控制的,主要就是先隐藏下拉菜单即设定其display为none,当点击分类的时候,出现下拉菜单和蒙版,而当手点击蒙版或者滑动的时候,下拉菜单和蒙版同时消失。
因为是手机webapp我使用了touchstart和touchmove,自我感觉touchstart在手机上触发比click好,其实click是一样的。一开始使用mousemove,发现手指在屏幕上移动是不会触发mousemove,这个应该只适用于pc网页
$(document).ready(function(){
$("#category").bind('touchstart', function(event){
if($("#show").css("display") == "none"){
$("#mban").addClass("mban");//添加蒙版样式
$("#show").css("display","inline");//显示下拉列表,我用ul写的
$("#show").addClass("show");//下拉菜单的位置样式等
}else{//当已经有下拉菜单时,点击则菜单与蒙版消失,分别移除样式并隐藏菜单
$("#mban").removeClass("mban");
$("#show").removeClass("show");
$("#show").css("display","none");
}
});
$("#mban").bind('touchstart', function(event){//点击蒙版时,下拉菜单与蒙版消失,分别移除样式并隐藏菜单
$("#mban").removeClass("mban");
$("#show").removeClass("show");
$("#show").css("display","none");
});
$("#mban").bind('touchmove', function(event){//在蒙版处滑动屏幕时,下拉菜单与蒙版消失,分别移除样式并隐藏菜单
$("#mban").removeClass("mban");
$("#show").removeClass("show");
$("#show").css("display","none");
});
});
- webapp上的蒙版,包含使用touchstart,touchmove
- webapp上的蒙版,包含使用touchstart,touchmove
- 移动端使用touchstart,touchmove,touchend实现图片轮播
- jQuery的touchstart,touchmove,touchend的获取位置
- 关于touch事件的使用 (touchStart touchMove touchEnd(不触发 android 4.0以上)) 滑动的使用
- 移动互联网终端的touch事务,touchstart, touchend, touchmove
- 移动互联网终端的touch事件,touchstart, touchend, touchmove
- touchstart,touchmove,touchend触摸事件的小小实践心得
- 移动互联网终端的touch事件,touchstart, touchend, touchmove
- 互联网终端的touch事件,touchstart, touchend, touchmove
- 移动互联网终端的touch事件,touchstart, touchend, touchmove
- 移动互联网终端的touch事件,touchstart, touchend, touchmove
- 移动互联网终端的touch事件,touchstart, touchend, touchmove
- HTML5屏幕触摸的四个事件touchstart、touchmove、touchend、touchcancel
- H5 touchstart、touchmove、touchend 拖拽
- 使用javascript实现手机上的touchmove效果
- 使用jq实现手机上的touchmove效果
- html 移动互联网终端的javascript touch事件,touchstart, touchend, touchmove
- Spring-boot搭建一个简单的Hello World工程
- Glide中centerCrop()与.transform()共用问题
- thinkphp5 数据库和模型详解 之1 数据库基础
- Java快速排序算法
- 关于Android的.so文件你所需要知道的
- webapp上的蒙版,包含使用touchstart,touchmove
- windows下 利用CoreAudio,Libmad,和3D环绕音效原理实现的MP3播放器
- linux 安装nginx
- linux 环境变量 export
- 美化CSDN博客--markdown编辑器中段落缩进、换行,改变字体、字号与颜色等
- 欢迎使用CSDN-markdown编辑器
- HDU2842 Chinese Rings
- 可查询最值的练习题
- Codeforces 363B Fence