基于zepto的手机焦点图touchstart touchmove

基于zepto的手机焦点图,查看地址:demo (建议使用手机浏览器查看)代码如下:

<!DOCTYPE HTML>

<html>

<head>

<title>zepto实现手机网站焦点图触屏划动效果</title>

<meta content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport"/>

<script src="" type="text/javascript" charset="utf-8"></script>

<style>

*{margin:0; padding:0;}

.focus{width:300px; overflow:hidden;}

.focus .con{width:1500px;overflow:hidden;}

.focus .con li{font-style:normal;width:300px;height:200px;background:#ccc;text-align:center;float:left;}

.focus .tit li{width:20%;float:left;}

.focus .tit li.on{background:#ccc;}

</style>

</head>

<body>

<div class="focus">

<ul class="con">

<li>1111</li>

<li>2222</li>

<li>3333</li>

<li>4444</li>

<li>5555</li>

</ul>

<ul class="tit">

<li class="on">1111</li>

<li>2222</li>

<li>3333</li>

<li>4444</li>

<li>5555</li>

</ul>

</div>

<script>

var touch={};

touch.current=0;

touch.lenght=4;

var touchElem=$(".focus ul")[0];

function move(elem,targetW,current){

elem.animate({

translate3d: targetW *current + "px,0,0"

},300,‘steps‘,function(){

});

}

function moveli(current){

//alert(elem.find("li"));

$(".tit > li").each(function(){

$(this).removeClass("on");

})

$(".tit > li").eq(current).addClass("on");

}

$(touchElem).unbind().bind("touchstart",function( e ){

touch.x1 = e.touches[0].pageX;

}).bind("touchmove",function( e ){

touch.x2 = e.touches[0].pageX;

touch.x3 = touch.endx+(touch.x2-touch.x1);

document.title=touch.x2-touch.x1;

$(this).css("-webkit-transform","translate3d("+touch.x3+"px, 0px, 0px)");

e.preventDefault();

}).bind("touchend",function( e ){

if(Math.abs(touch.x2 - touch.x1) >=30){

touch.i = touch.x2 - touch.x1 > 0 ? -1 : 1;

touch.current=touch.current+touch.i;

if(touch.current==-1){touch.current=0}else if (touch.current>=touch.lenght){touch.current=touch.lenght;}

}

document.title=touch.current;

touch.endx=touch.current*-300;

move($(this),-300,touch.current);

moveli(touch.current);

}).bind(‘touchcancel‘, function(){

})

</script>

</body>

</html>

时间: 2024-08-24 12:28:30

基于zepto的手机焦点图touchstart touchmove的相关文章

iscroll4 捕捉元素开发手机焦点图滑动效果

html标准代码格式 1 <div id="wrapper"> 2 <div id="scroller" > 3 <ul id="thelist"> 4 <li><img src="img/showpic_1.jpg"/></li> 5 <li><img src="img/showpic_2.jpg"/><

基于zepto.js的模仿手机QQ空间的大图查看组件ImageView.js

调用方式 :ImageView(index,imgData)  --index参数 为图片默认显示的索引值,类型 为Number  --imaData参数 为图片url数组 ,类型为Array 使用之前要先引入 zepto.js 文件 ImageView.js具体代码如下: /* * ImageView v1.0.0 * --口袋蓝房网 基于zepto.js的大图查看 * --调用方法 ImageView(index,imgDada) * --index 图片默认值显示索引,Number --i

基于zepto的插件之移动端无缝向上滚动并上下触摸滑动

该插件乃本博客作者所写,目的在于提升作者的js能力,也给一些js菜鸟在使用插件时提供一些便利,老鸟就悠然地飞过吧. 公司的移动端项目是基于zepto的,有一个页面要求文字能够无缝地不停向上滚动,但查了网上的资料,大多都是基于jquery的,虽然稍作修改就可以用于移动端,但不能实现触摸上下翻滚.所以就去了zepto的官网查看其API,却发现如果要使用zepto的swipe()方法,需要引用其已经封装好的touch.js文件,我就赶紧引用了这个js文件,可在实际测试中,官网给出的touch.js文件

获取touchstart,touchmove,touchend 坐标

简单说下如何用jQuery 和 js原生代码获取touchstart,touchmove,touchend 坐标值: jQuery 代码: $('#id').on('touchstart',function(e) { var _touch = e.originalEvent.targetTouches[0]; var _x= _touch.pageX; }); $('#id').on('touchmove',function(e) { var _touch = e.originalEvent.t

基于Zepto的Alert提示框开源框架Tiny-Alert

项目主页:http://shootyou.github.io/Tiny-Alert/ 什么是Tiny-Alert? 这是一个基于Zepto的提示框插件,在移动端使用会有更好的效果.它被设计成是移动端原生alert和confirm提示框的更美观替代品.同时它还实现了一个loading效果.它的核心代码参考了rDailog,在它基础上适配了zepto,去掉了移动端用不到的特性,另外让它看上去更美观了. 它有如下特性: 轻量级,代码量不超过300行,压缩后仅2k. 基于zepto更适合移动端. 支持回

OGEngine —— 基于JAVA的手游开发开源引擎

OGEngine是国际著名开源引擎AndEngine的一个分支,遵循LGPL开源协议使用OpenGL ES进行图形绘制.同时集成了Box2D物理引擎,因此可以实现复杂的物理效果. OGEngine主要使用Java语言开发,但在大运算量的耗时功能时,OGEngine使用了C/C++本地代码进行开发.比如物理引擎及音频处理.作为用户,你只需要关注Java端就可以了,它已经把所有的本地代码封装好了.相比于其他android游戏引擎,OGEngine的效率优势十分明显. AndEngine在国际上已成为

jQuery的touchstart,touchmove,touchend的获取位置

$('#webchat_scroller').on('touchstart',function(e) { var touch = e.originalEvent.targetTouches[0]; var y = touch.pageY; }); $('#webchat_scroller').on('touchmove',function(e) { var touch = e.originalEvent.targetTouches[0]; var y = touch.pageY; }); $('

基于zepto判断mobile的横竖屏状态

借用jquery mobile中的代码,删除了一些多余的部分,简单的基于zepto的模块 var CheckOrientation = (function(){ var win = $( window ), get_orientation, last_orientation, initial_orientation_is_landscape, initial_orientation_is_default, portrait_map = { "0": true, "180&qu

手机端touchstart,touchmove,touchend事件,优化用户划入某个可以点击LI的效果

在我们滑动手机的时候,如果LI或者DIV标签可以点击,那么在移动端给用户一个效果 /*id为添加效果LI上的UL的ID,或者是当前DIV的ID*/ function doTouchPublic(id){ setTimeout(function(){ var obj=document.getElementById(id); touchPublic.tagUltagDiv(obj); },300); }; var touchPublic={ tagUltagDiv:function(obj){ va