html5 touch事件中touched事件怎么用?有例子么?

HTML5 PHONEGAP android获取用户触屏事件代码怎么写_百度知道
HTML5 PHONEGAP android获取用户触屏事件代码怎么写
我有更好的答案
按默认排序
您高兴能帮助您document注册事件 touchstart, touchmove, touchend事件调函数 pageX, pageY 属性参考: 采纳我前进力记评采纳答题易互相帮助
其他类似问题
phonegap的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁2299人阅读
WebSocket protocol 是HTML5一种新的协议(protocol)。它是实现了浏览器与服务器全双工通信(full-duplex)。
现在,很多网站为了实现即时通讯(real-time),所用的技术都是轮询(polling)。轮询是在特定的的时间间隔(time interval)(如每1秒),由浏览器对服务器发出HTTP request,然后由服务器返回最新的数据给客服端的浏览器。这种传统的HTTP request d的模式带来很明显的缺点 – 浏览器需要不断的向服务器发出请求(request),然而HTTP request 的header是非常长的,里面包含的数据可能只是一个很小的值,这样会占用很多的带宽。
而最比较新的技术去做轮询的效果是Comet – 用了AJAX。但这种技术虽然可达到全双工通信,但依然需要发出请求(reuqest)。
在 WebSocket API,浏览器和服务器只需要要做一个握手的动作,然后,浏览器和服务器之间就形成了一条快速通道。两者之间就直接可以数据互相传送。在此WebSocket 协议中,为我们实现即使服务带来了两大好处:
互相沟通的Header是很小的-大概只有 2 Bytes
2. Server Push
服务器可以主动传送数据给客户端
下面实现一个简单PUSH例子如下:
服务端代码:
public class InitServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static List&MessageInbound& socketL
public void init(ServletConfig config) throws ServletException {
InitServlet.socketList = new ArrayList&MessageInbound&();
super.init(config);
System.out.println(&Server start============&);
public static List&MessageInbound& getSocketList() {
return InitServlet.socketL
public class TestWebSocketServlet extends WebSocketServlet{
private static final Logger log = Logger.getLogger(TestWebSocketServlet.class);
private static final long serialVersionUID = 1L;
//存储链接的容器
private &static &List&WebSocketMessageInbound& connsList = new ArrayList&WebSocketMessageInbound&();
protected StreamInbound createWebSocketInbound(String subProtocol,HttpServletRequest request) {
// TODO Auto-generated method stub
return new WebSocketMessageInbound();
public class WebSocketMessageInbound extends MessageInbound{
@Override &
& &protected void onClose(int status) { &
// & & & &InitServlet.getSocketList().remove(this); &
super.onClose(status); &
log.debug(&onClose&);
InitServlet.getSocketList().remove(this);
& &@Override &
& &protected void onOpen(WsOutbound outbound) { &
& & log.debug(&onOpen&);
& & & &super.onOpen(outbound); &
& & & &InitServlet.getSocketList().add(this);
protected void onBinaryMessage(ByteBuffer message) throws IOException {
// TODO Auto-generated method stub
log.debug(&onBinaryMessage&);
protected void onTextMessage(CharBuffer message) throws IOException {
// TODO Auto-generated method stub
log.debug(&onTextMessage=&+message);
// this.getWsOutbound().writeTextMessage(CharBuffer.wrap(&====&));
// this.getWsOutbound().writeTextMessage(message);
//发送给所有链接的
for (MessageInbound messageInbound : InitServlet.getSocketList()) { &
& & & & & &CharBuffer buffer = CharBuffer.wrap(message); &
& & & & & &WsOutbound outbound = messageInbound.getWsOutbound(); &
& & & & & &outbound.writeTextMessage(buffer); &
& & & & & &outbound.flush(); &
& & & &} &
web.xml配置
&!-- WebSocket --&
&servlet-name&initServlet&/servlet-name&
&servlet-class&com.demo.websocket.InitServlet&/servlet-class&
&load-on-startup&1&/load-on-startup&
&/servlet&
&servlet-name&websocket&/servlet-name&
&servlet-class&com.demo.websocket.TestWebSocketServlet&/servlet-class&
&/servlet&
&servlet-mapping&
&servlet-name&websocket&/servlet-name&
&url-pattern&/websocket&/url-pattern&
&/servlet-mapping&
前台代码:
& & &head&&
& & & & &title&WebSoket Demo&/title&&
& & & & &script type=&text/javascript&&&
& & & & & & //验证浏览器是否支持WebSocket协议
& & & & & & if (!window.WebSocket) {&
& & & & & & & & alert(&WebSocket not supported by this browser!&);&
& & & & & & }&
& & & & & & &
& & & & & & function display() {&
& & & & & & & & //var valueLabel = document.getElementById(&valueLabel&);&
& & & & & & & & //valueLabel.innerHTML = &&;&
& & & & & & & & ws=new WebSocket(&ws://localhost:8082/springmvc/websocket&);&
& & & & & & & & //监听消息
& & & & & & & & ws.onmessage = function(event) {&
& & & & & & & & & & //valueLabel.innerHTML+ = event.&
& & & & & & & & & & log(event.data);
& & & & & & & & };&
& & & & & & & & // 打开WebSocket&
& & & & & & & & ws.onclose = function(event) {&
& & & & & & & & & //WebSocket Status:: Socket Closed
& & & & & & & & };&
& & & & & & & & // 打开WebSocket
& & & & & & & & ws.onopen = function(event) {&
& & & & & & & & & &//WebSocket Status:: Socket Open
& & & & & & & & & & //// 发送一个初始化消息
& & & & & & & & & & ws.send(&Hello, Server!&);&
& & & & & & & & };&
& & & & & & & & ws.onerror =function(event){
& & & & & & & & & & //WebSocket Status:: Error was reported
& & & & & & & & };
& & & & & & }&
& & & & & & var log = function(s) { &
& &if (document.readyState !== &complete&) { &
& & & &log.buffer.push(s); &
& &} else { &
& & & &document.getElementById(&contentId&).innerHTML += (s + &\n&); &
& & & & & & function sendMsg(){
& & & & & & & & var msg=document.getElementById(&messageId&);
& & & & & & & & //alert(msg.value);
& & & & & & & & ws.send(msg.value);&
& & & & & & }
& & & & &/script&&
& & &/head&&
& & &body onload=&display();&&&
& & & & &div id=&valueLabel&&&/div&&
& & & & &textarea rows=&20& cols=&30& id=&contentId&&&/textarea&
& & & & &br/&
& & & & &input name=&message& id=&messageId&/&
& & & & &button id=&sendButton& onClick=&javascript:sendMsg()& &Send&/button&
& & &/body&&
备注:必须把TOMCAT7 &lib目录下的两个jar文件catalina.jar、tomcat-coyote.jar添加到项目的lib。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:183206次
积分:1502
积分:1502
排名:第11820名
原创:39篇
转载:15篇
评论:43条
(2)(1)(1)(3)(2)(3)(3)(1)(1)(2)(1)(1)(2)(3)(3)(2)(3)(1)(1)(3)(1)(2)(1)(1)(1)(2)(3)(1)(3)扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
ExtJS中运用HTML5 Canvas简单例子
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口html5怎么做音频点播 即点即播的那种 能否给个例子?_百度知道
html5怎么做音频点播 即点即播的那种 能否给个例子?
提问者采纳
ajax+&audio&
提问者评价
其他类似问题
html5的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 默认配置与事件基础 | Kayo's Melody
这个二维码是神马?
用移动设备的摄像头扫描右侧的二维码,您可以 ——
关注这个独立博客的微信公众号并随时获取本博客的日志
具体可以参考
你可能也喜欢

我要回帖

更多关于 html5 video 事件 的文章

 

随机推荐