39,082
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta content="telephone=yes" name="format-detection" />
<meta name="apple-mobile-web-app-status-bar-style" content="white">
<meta name="x5-fullscreen" content="true">
<meta name="apple-touch-fullscreen" content="yes">
<title>Document</title>
<style>
*{margin:0;padding:0;}
.box{
height:200px;
width:100%;
overflow: hidden;
}
.movebox{
height:200px;
width:9000px;
padding:0;
position:relative;
left:0;
}
.movebox li{
height:200px;
float:left;
list-style:none;
font-size:30px;
color:#fff;
}
</style>
<script>
window.onload = function(){
var moveX, //手指滑动距离
endX, //手指停止滑动时X轴坐标
cout = 0, //滑动计数器
moveDir; //滑动方向
var movebox = document.querySelector(".movebox"); //滑动对象
var Li = movebox.querySelectorAll("li"); //滑动对象item
var width = parseInt(window.getComputedStyle(movebox.parentNode).width); //滑动对象item的宽度
movebox.style.width = (width*4) + "px"; //设置滑动盒子width
for(var i = 0; i < Li.length; i++){
Li[i].style.width = width + "px"; //设置滑动item的width,适应屏幕宽度
}
//触摸开始
function boxTouchStart(e){
var touch = e.touches[0]; //获取触摸对象
startX = touch.pageX; //获取触摸坐标
endX = parseInt(movebox.style.webkitTransform.replace("translateX(", "")); //获取每次触摸时滑动对象X轴的偏移值
}
function boxTouchMove(e){
var touch = e.touches[0];
moveX = touch.pageX - startX; //手指水平方向移动的距离
if(cout == 0 && moveX > 0){ //刚开始第一次向左滑动时
return false;
}
if(cout == 3 && moveX < 0){ //滑动到最后继续向右滑动时
return false;
}
movebox.style.webkitTransform = "translateX(" + (endX + moveX) + "px)"; //手指滑动时滑动对象随之滑动
}
function boxTouchEnd(e){
moveDir = moveX < 0 ? true : false; //滑动方向大于0表示向左滑动,小于0表示向右滑动
//手指向左滑动
if(moveDir){
if(cout<3){
movebox.style.webkitTransform = "translateX(" + (endX-width) + "px)";
cout++;
}
//手指向右滑动
}else{
//滑动到初始状态时返回false
if(cout == 0){
return false;
}else{
movebox.style.webkitTransform = "translateX(" + (endX+width) + "px)";
cout--;
}
}
}
//滑动对象事件绑定
movebox.addEventListener("touchstart", boxTouchStart, false);
movebox.addEventListener("touchmove", boxTouchMove, false);
movebox.addEventListener("touchend", boxTouchEnd, false);
}
</script>
</head>
<body style="position:absolute;width:100%;overflow:hidden;">
<div class="box">
<ul class="movebox" style="transition-duration:0.2s;transform: translateX(-0px);">
<li style="background:red;">1</li>
<li style="background:yellow">2</li>
<li style="background:blue">3</li>
<li style="background:green">4</li>
</ul>
</div>
</body>
</html>
<!DOCTYPE html><html><head><meta charset="utf-8"><title>banner切换实现</title><style type="text/css">/** @description: banner切换样式* @author: lanfeng(beryl)* @time:2013-02-26*//* reset*/*{ margin: 0; padding: 0;}body{font:12px/1.5 Tahoma,'/5B8B/4F53',arial,Tahoma,helvetica,sans-serif; color:#333333;background-color:#ffffff;position:relative; }h1,h2,h3,h4,h5,h6{font-size:100%}address,em{font-style:normal;}code,kbd,pre,samp{font-family:courier new,courier,monospace;}ul,ol{list-style:none outside none;}fieldset,img{border:0;}img{vertical-align:middle}table{border-collapse:collapse;border-spacing:0;font-size:inherit;*font-size:100%;}input,button,textarea,select{vertical-align:middle;font:100% Helvetica,Arial,sans-serif; color:inherit}.clearfix:after{content:'.';display:block;height:0;clear:both;visibility:hidden;}.clearfix{*zoom:1;}.clear{font-size:0;line-height:0;height:0;clear:both;visibility:hidden;overflow:hidden;}.d-ftab{ width:510px; height: 180px;position: relative; margin: 100px auto;}.d-fShow ul li{ float: left; width: 510px; height: 180px;}.d-fShow{ width: 510px; height: 180px; overflow: hidden;}.d-fShow img{ width: 510px; height: 180px; float: left;}.d-fs-control{ position: absolute; width:510px; position: absolute; left: 0; bottom: 0; height: 25px; line-height: 25px;background: rgba(0,0,0,0.4);filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#66000000',EndColorStr='#66000000') ; }:root .d-fs-control{filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#66000000',EndColorStr='#66000000')/9 ;}.d-fs-control ul{ position: absolute; bottom:3px; right: 5px; height: 16px;}.d-fs-control ul li{width:16px;height:16px; background:#777675;border-radius: 2px 2px 2px 2px; float:left;margin-left:5px;color:#dcdcdc;text-align:center;font-weight:700;cursor:pointer;line-height:16px;filter: alpha(opacity=70); opacity: 0.7;}.d-fs-control ul li:hover,.d-fs-control ul li.select{background:#ffffff;color:#ff6700;}</style><script type="text/javascript" src="js/jquery-1.4.2.min.js"></script><script type="text/javascript">$(function(){var wrap =$('.d-ftab');var imgs = wrap.find('.d-fShow ul >li');var len=imgs.length ;var tabTime=100;var outTime=4000;var select='select';var num =0 ;var interval;var type = 'click';var btns=wrap.find('.d-fs-control ul>li');btns.bind(type,function(){var _this=$(this);_this.addClass('select').siblings ().removeClass('select');num=_this.prevAll().length;imgs.stop().eq(num).fadeTo(tabTime,1) ;imgs.not(':eq('+num+')').filter(':visible').fadeOut(tabTime) ;return false;}).eq(num).trigger(type);var interFunc=function(){num=(num+1)%len;btns.eq(num).triggerHandler(type);}wrap.bind('mouseover',function(){clearInterval(interval);}).bind('mouseout',function(){interval=setInterval(interFunc,outTime)})})</script></head><body><div class="d-ftab"><div class="d-fShow"><ul><li><a href="#"><img alt="" src=" images/1.jpg"/></a></li><li ><a href="#"><img alt="" src="images/2.png"></a></li><li><a href="#"><img alt="" src="images/3.jpg"></a></li><li><a href=""><img alt="" src="images/4.jpg"></a></li><li><a href="#"><img alt="" src="images/5.jpg"></a></li></ul></div><div class="d-fs-control"><ul><li>1</li><li>2</li><li>3</li><li>4</li><li class="select">5</li></ul></div></div></body></html>
业余草
CODE大全
请多结帖!