jquery 移动端轮播图
<div class="slide">
<div class="slide-box">
<ul class="slide-ul">
<li><a href="" title="1111"><img src="http://www.heibaipig.com/demo/images/test/1.jpg"></a></li>
<li><a href="" title="2222"><img src="http://0.thumb.pc6.com/up/2016-5/20165199297.jpg"></a></li>
<li><a href="" title="33333"><img src="http://0.thumb.pc6.com/up/2016-4/201642814841.jpg"></a></li>
<li><a href="" title="44444"><img src="http://m.pc6.com/public/img/20151202.jpg"></a></li>
</ul>
</div>
<div class="title-box"><p class="title">1111</p><span class="circle"><em class="active"></em><em></em><em></em><em></em></span></div>
</div>
*{ padding:; margin:;}
/*.slide{position:relative}
.slide-box{height:100%; margin:0 auto;position:relative; overflow:hidden}
.slide ul{ position:absolute; left:0; top:0; width:100%; min-height:160px;}
.slide ul li{ float:left; list-style:none; position:relative}
.slide ul li img{ width:100%; height:100%;}*/ /* focus_pic */
.slide{clear:both;position:relative;z-index:;width:100%;max-width:960px;max-height:480px;margin:0 auto 0.3em auto;overflow:hidden;}
.slide-box{ width:100%;height:100%; margin:0 auto;position:relative; overflow:hidden}
.slide .slide-ul{position:absolute;z-index:;left:;width:10000px;}
.slide .slide-ul li{float:left;display:block;}
.slide .slide-ul li img{display:block;width:100%;height:100%;}
.slide .title-box{ width:90%; padding:0 5%; z-index:; height:30px; line-height:30px; color:#fff; font-size:14px; background:rgba(0,0,0,.5); position:absolute; left:; bottom:;}
.slide .circle{ float:right;}
.slide .title{ float:left; display:inline-block;}
.slide .circle em{ display:inline-block; width:5px; height:5px; margin-left:5px; background-color:#fff; border-radius:50%;}
.slide .circle .active{ background-color:#f00}
<script>
//自适应
function sizeShow(){
var pic_w=$(window).width();
var pic_h=pic_w*0.5;
$(".slide").height(pic_h);
$(".slide li").width(pic_w).height(pic_h);
$(".slide ul").width(pic_w*4)
}; function scrollAuto(){
sizeShow();
$(window).resize(function(){sizeShow()});
var oclass=$(".slide");
var w=oclass.find("li").width();
var iNow = 0, index = 1, timer = null;
var touch={
"s":[],
"m":[],
"e":[],
"d":""
}; oclass[0].addEventListener('touchstart', function(e){
touch.s[0] = e.targetTouches[0].pageX;
touch.s[1] = e.targetTouches[0].pageY;
touch.s[2] = (new Date()).getTime();
clearInterval(timer)
}, false); oclass[0].addEventListener('touchmove', function(e){
var a=Math.abs(e.targetTouches[0].pageX-touch.s[0])
var b=Math.abs(e.targetTouches[0].pageY-touch.s[1]);
console.log("dMove:"+touch.d)
if(a>=b && touch.d==""){
touch.d=1;//左右
//touch.m[0]=touch.s[0]
}else if(touch.d==""){
touch.d=0;//上下或者偏上下
}
console.log(a+":::"+b)
if(touch.d==1){//左右滚动
e.preventDefault();
$(".slide ul").css({"left":-iNow*w+e.targetTouches[0].pageX-touch.s[0]});
// touch.m[0]=e.targetTouches[0].pageX;
//touch.m[1]=e.targetTouches[0].pageY;
} }, false); oclass[0].addEventListener('touchend', function(e){
console.log("dEnd:"+touch.d)
if(touch.d==1){
if((new Date()).getTime()-touch.s[2]>700){
if(e.changedTouches[0].pageX-touch.s[0]>w/3){
auto("right")
}else if(touch.s[0]-e.changedTouches[0].pageX>w/3){
auto("left")
}else{
auto("reset")
}
}else{
if(e.changedTouches[0].pageX>touch.s[0]){
auto("right");
}else if(touch.s[0]>e.changedTouches[0].pageX){
auto("left")
}
}
}
touch.d="";
timer=setInterval(function(){
if(iNow>=$(".slide li").length-1){
iNow=0;
}else{
iNow++
}
$(".slide ul").animate({"left":-w*iNow})
$(".circle em").eq(iNow).addClass("active").siblings().removeClass("active");
$(".title-box .title").html($(".slide li").eq(iNow).find("a").attr("title"))
},3000); }, false); function auto(c){
if(c=="left"){
if(iNow>=$(".slide li").length-1){
iNow=$(".slide li").length-1
}else{
iNow++
}
console.log(iNow)
$(".slide ul").animate({"left":-w*iNow})
}else if(c=="right"){
if(iNow<=0){
iNow=0
}else{
iNow--
}
$(".slide ul").animate({"left":-w*iNow})
}else if(c=="reset"){
$(".slide ul").animate({"left":-w*iNow})
}
$(".circle em").eq(iNow).addClass("active").siblings().removeClass("active");
$(".title-box .title").html($(".slide li").eq(iNow).find("a").attr("title"))
}; timer=setInterval(function(){
if(iNow>=$(".slide li").length-1){
iNow=0;
}else{
iNow++
}
$(".slide ul").animate({"left":-w*iNow})
$(".circle em").eq(iNow).addClass("active").siblings().removeClass("active");
$(".title-box .title").html($(".slide li").eq(iNow).find("a").attr("title"))
},3000); }
$(function(){
scrollAuto();
}) </script>
实现效果:
jquery 移动端轮播图的更多相关文章
- 原生js实现简单移动端轮播图
最近项目不是很忙,自己就用原生js写了一个简单的移动端轮播图的小demo,可实现自动轮播和手势滑动轮播,然后就把它记录到个人博客里.还有很多不足的地方,希望多多指出,以便改进. 1.代码部分 分为四个 ...
- jQuery淡入淡出轮播图实现
大家好我是 只是个单纯的小白,这是人生第一次写博客,准备写的内容是Jquery淡入淡出轮播图实现,在此之前学习JS写的轮播图效果都感觉不怎么好,学习了jQuery里的淡入淡出效果后又写了一次轮播图效果 ...
- 告别组件之教你使用原生js和css写移动端轮播图
在工作中由于项目需要要写一个轮播图,本想使用组件直接调用实现快速开发,但是一想到自己经常使用组件但是让自己手写的话确实一点都不会. 一个不会手写组件的前端程序员不是一个好程序员!于是打算自己手写一个. ...
- 移动端轮播图vue-awesome-swiper
日常写设计文档,日常写Demo,写轮播图的时候觉得bootstrap不适合移动端,或者说不是轻量级的,于是换成Swiper,但是写的时候才发现怎么把这东西嵌到Vue里面啊? Σ( ° △ °|||)︴ ...
- 用jQuery写的轮播图
效果图: GitHub地址:https://github.com/123456abcdefg/Javascript 大家可以下载源码查看. 与前一篇写的轮播图实现的效果一致,这个是用jQuery写的, ...
- jQuery实现简易轮播图的效果
(图片素材取自于小米官网) 刚开始接触jQuery的学习,个人觉得如果为了实现多数的动态效果,jQuery的确很简易方便. 下面简易的轮播图效果,还请前辈多多指教~ (努力学习react vue an ...
- 移动端轮播图实现方法(dGun.js)
本文章介绍在移动端无缝隙轮播图实现的原理,这个轮子比较简单,但可以方便刚刚入门的同学参考.最终效果是在移动端无缝隙无限滑动,可以自定义轮播的速度.支持手势左右滑动.最后会放上源码. HTML部分 &l ...
- 用纯css、JavaScript、jQuery简单的轮播图
完成一个可以自动切换或点击数字的轮播图 HTML代码只需要一个div 包含着一个图片和一个列表,我们主要的思路就是通过点击相应的数字,改变图片的 路径. 有4张图片都在img文件夹里,名称为 img ...
- 原生JS实现移动端轮播图
功能描述: 自动无缝轮播图片,底部小圆点跟图片保持一致:手指左右移动轮播图,移动距离大于50px播放下一张(或上一张),小于50px则回弹 具体功能实现: 1.定时器 自动轮播图片 先声明一个inde ...
随机推荐
- HDU1061-Rightmost Digit(高速功率模)
pid=1061">主题链接 题意:求n^n的个位数的值. 思路:高速幂求值 代码: #include <iostream> #include <cstdio> ...
- (大数据工程师学习路径)第一步 Linux 基础入门----环境变量与文件查找
环境变量与文件查找 本节介绍环境变量的作用与用法,及几种搜索文件的方法.学会这些技巧高效地使用 Linux. 一.环境变量 1.变量 要解释环境变量,得先明白变量是什么,准确的说应该是 Shell 变 ...
- poj2443(简单的状态压缩)
POJ2443 Set Operation Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2679 Accepted: ...
- 中国人被“清朝GDP世界第一”忽悠了!
中国人被"清朝GDP世界第一"忽悠了!"鸦片战争前的清朝GDP世界第一",这一说法在中国流传非常广.追根溯源,最早提出这一观点的似乎是英国学者麦迪森,他的一项猜 ...
- [置顶] 纯手工打造漂亮的瀑布流,五大插件一个都不少Bootstrap+jQuery+Masonry+imagesLoaded+Lightbox!
前两天写的文章<纯手工打造漂亮的垂直时间轴,使用最简单的HTML+CSS+JQUERY完成100个版本更新记录的华丽转身!>受到很多网友的喜爱,今天特别推出姊妹篇<纯手工打造漂亮的瀑 ...
- NYNU_省赛选拔题(10)
题目描述 Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recog ...
- 多层次的Json字符串转化为对象
using Arvato.CRM.DataTrans.ConsoleHost.Model;using System;using System.Collections.Generic;using Sys ...
- C#关于HttpClient的统一配置(一)
public class BaseHttpClient { protected string contentType; public BaseHttpClient() { this.contentTy ...
- maven_基本配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 位记录——Windows 7已安装Sublime Text 3、cynwin、SublimeClang
转载请注明出处:http://blog.csdn.net/cywosp/article/details/34429697 1. 到https://www.cygwin.com/下载setup-x86_ ...