下面是自己找网上资料写的一个小demo,基础的属性和方法都有用到,但是用法还不是很标准,github上的demo用法很标准,外面一个wrapper,里面还得有一个scroller,如果要做跑马灯效果还要在外面套一个viewport。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
*{margin:0; padding:0;}
html{font-size: 2.5rem;}
li{list-style:none;}
div#wrapper{height:400px; overflow: hidden;}
div#wrapper ul{width:100%;}
div#wrapper li{width:100%; text-align: center; padding:20px; border:1px solid #eee; cursor: pointer;}
div#wrapper li:hover{background: #eee;}
</style>
</head>
<body>
<div id="wrapper">
<ul>
<li>test1</li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
<li>test5</li>
<li>test6</li>
</ul>
</div> <script src="./js/jquery-1.11.3.min.js"></script>
<script src="./js/iscroll.js"></script>
<script src="./js/iscroll-probe.js"></script>
<script type="text/javascript">
var myscroll = new IScroll("#wrapper", {
probeType: 3,
bounceEasing: 'elastic',
bounceTime: 1200
}); myscroll.on("scrollEnd", function(){
if(myscroll.directionY == -1){
console.log("slide down");
}else if(myscroll.directionY == 1){
console.log("slide up");
} console.log("(" + myscroll.maxScrollX + "," + myscroll.maxScrollY + ")" + "is the max (x,y) point of this scroller"); var appendId = $("#wrapper>ul>li").length + 1;
$("#wrapper>ul").append("<li>test" + appendId + "</li>"); var y = $("#wrapper").height() - $("#wrapper>ul").height();
myscroll.refresh();
//myscroll.scrollTo(0, y);
myscroll.scrollTo(myscroll.maxScrollX, myscroll.maxScrollY); console.log("scrollEnd");
}); myscroll.on("beforeScrollStart", function(){
console.log("beforeScrollStart");
}); myscroll.on("scrollCancel", function(){
console.log("scrollCancel");
}); myscroll.on("scrollStart", function(){
console.log("scrollStart");
}); myscroll.on("scroll", function(){
console.log("scroll");
}); myscroll.on("flick", function(){
console.log("flick");
}); myscroll.on("zoomStart", function(){
console.log("zoomStart");
}); myscroll.on("zoomEnd", function(){
console.log("zoomEnd");
});
</script>
</body>
</html>

下面是github上的例子,barebone,基础框架,如果要写iScroll,就在这样的基础上写。代码作了一些修改,灵活性更加好。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<title></title>
<style type="text/css">
body {
/* On modern browsers, prevent the whole page to bounce */
overflow: hidden;
} #wrapper {
position: relative;
width: 300px;
height: 300px;
overflow: hidden; /* Prevent native touch events on Windows */
-ms-touch-action: none; /* Prevent the callout on tap-hold and text selection */
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none; /* Prevent text resize on orientation change, useful for web-apps */
-webkit-text-size-adjust: none;
-moz-text-size-adjust: none;
-ms-text-size-adjust: none;
-o-text-size-adjust: none;
text-size-adjust: none;
} #scroller {
position: absolute; /* Prevent elements to be highlighted on tap */
-webkit-tap-highlight-color: rgba(0,0,0,0); /* Put the scroller into the HW Compositing layer right from the start */
-webkit-transform: translateZ(0);
-moz-transform: translateZ(0);
-ms-transform: translateZ(0);
-o-transform: translateZ(0);
transform: translateZ(0);
}
</style>
</head>
<body> <div id="wrapper">
<div id="scroller">
<p><strong>This demo shows the minimum CSS/HTML/JS configuration you need to run the iScroll. Look at the source code for details.</strong></p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p> <p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.</p>
</div>
</div> <script src="./js/jquery-1.11.3.min.js"></script>
<script src="./js/iscroll.js"></script>
<script src="./js/iscroll-probe.js"></script>
<script type="text/javascript">
var myScroll; function loaded () {
myScroll = new IScroll('#wrapper');
} document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); window.addEventListener("load",loaded,false);
</script>
</body>
</html>

用iScroll写幻灯片/跑马灯/焦点图/indicator/指示器

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<title></title>
<style type="text/css">
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
} html {
-ms-touch-action: none;
} body, ul, li {
padding: 0;
margin: 0;
border: 0;
} body {
font-size: 12px;
font-family: ubuntu, helvetica, arial;
overflow: hidden; /* this is important to prevent the whole page to bounce */
} #viewport {
position: relative;
width: 320px;
height: 240px;
margin: 0 auto;
background: #444;
overflow: hidden;
} #wrapper {
width: 200px;
height: 240px;
margin: 0 auto;
} #scroller {
position: absolute;
z-index: 1;
-webkit-tap-highlight-color: rgba(0,0,0,0);
width: 800px;
height: 240px;
-webkit-transform: translateZ(0);
-moz-transform: translateZ(0);
-ms-transform: translateZ(0);
-o-transform: translateZ(0);
transform: translateZ(0);
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-text-size-adjust: none;
-moz-text-size-adjust: none;
-ms-text-size-adjust: none;
-o-text-size-adjust: none;
text-size-adjust: none;
background-color: #444;
} .slide {
width: 200px;
height: 240px;
float: left;
} .painting {
width: 140px;
height: 200px;
border-radius: 10px;
margin: 20px auto;
border: 1px solid #000;
box-shadow:
inset 2px 2px 6px rgba(255,255,255,0.6),
inset -2px -2px 6px rgba(0,0,0,0.6),
0 1px 8px rgba(0,0,0,0.8);
} .giotto {
background: url(./img/giotto.jpg);
} .leonardo {
background: url(./img/leonardo.jpg);
} .gaugin {
background: url(./img/gaugin.jpg);
} .warhol {
background: url(./img/warhol.jpg);
} #indicator {
position: relative;
width: 110px;
height: 20px;
margin: 10px auto;
background: url(./img/dot.png);
} #dotty {
position: absolute;
width: 20px;
height: 20px;
border-radius: 10px;
background: #777;
}
</style>
</head>
<body> <div id="viewport">
<div id="wrapper">
<div id="scroller">
<div class="slide">
<div class="painting giotto"></div>
</div>
<div class="slide">
<div class="painting leonardo"></div>
</div>
<div class="slide">
<div class="painting gaugin"></div>
</div>
<div class="slide">
<div class="painting warhol"></div>
</div>
</div>
</div>
</div> <div id="indicator">
<div id="dotty"></div>
</div> <script src="./js/jquery-1.11.3.min.js"></script>
<script src="./js/iscroll.js"></script>
<script src="./js/iscroll-probe.js"></script>
<script type="text/javascript">
var myScroll; function loaded () {
myScroll = new IScroll('#wrapper',{
scrollX: true,
scrollY: false,
momentum: false, //关闭动量动画
snap: true, //分割页面,根据元素分割
snapSpeed: 400,
keyBindings: true, //绑定键盘事件
indicators: { //指示器
el: document.getElementById('indicator'),
resize: false
}
});
} document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); window.addEventListener("load",loaded,false);
</script>
</body>
</html>

http://www.tuicool.com/articles/vMn2u2

iscroll demo的更多相关文章

  1. iscroll 下拉刷新功能

    版本号:iscroll4.2.5.js iscroll 版本很有关系  在线: demo链接   有出现白屏的bug,将iscroll版本改成iscroll4.2.5就可以了 html <!DO ...

  2. 【iScroll源码学习04】分离IScroll核心

    前言 最近几天我们前前后后基本将iScroll源码学的七七八八了,文章中未涉及的各位就要自己去看了 1. [iScroll源码学习03]iScroll事件机制与滚动条的实现 2. [iScroll源码 ...

  3. 【iScroll源码学习01】准备阶段

    前言 我们昨天初步了解了为什么会出现iScroll:[SPA]移动站点APP化研究之上中下页面的iScroll化(上),然后简单的写了一个demo来模拟iScroll,其中了解到了以下知识点: ① v ...

  4. iscroll动态加载数据完美解决方案

    @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...

  5. HTML5应用开发:JavaScript库iScroll教程

    目录 1. iScroll介绍 2. 安装和使用 3. 简单的iScroll例子 4. Pinch & Zoom 5. Snap to element 6. iScroll 详细参数 1. i ...

  6. 【iScroll源码学习01】准备阶段 - 叶小钗

    [iScroll源码学习01]准备阶段 - 叶小钗 时间 2013-12-29 18:41:00 博客园-原创精华区 原文  http://www.cnblogs.com/yexiaochai/p/3 ...

  7. iScroll.js 向上滑动异步加载数据回弹问题

    iScroll是一款用于移动设备web开发的一款插件.像缩放.下拉刷新.滑动切换等移动应用上常见的一些效果都可以轻松实现. 现在最新版本是5.X,官网这里:http://iscrolljs.com/ ...

  8. iscroll 4 下拉 上拉 加载

    <!DOCTYPE html> iScroll demo: barebone body, ul, li{ padding:0; margin: 0; border:0; } body{ f ...

  9. iScroll示例,下拉刷新,上拉刷新

    iScroll示例,下拉刷新,上拉刷新 <!DOCTYPE html> <html> <head> <meta http-equiv="Conten ...

随机推荐

  1. week4b:个人博客作业

    下面是week4做程序的过程. 1.在做之前先做客户需求,要求使用的使用mul图. 自己第一次听到这个名字,网上查UML为, http://www.cnblogs.com/wangkangluo1/a ...

  2. 24_IO_第24天(转换流、缓冲流)_讲义

    今日内容介绍 1.转换流 2.缓冲流 01转换流概述 * A: 转换流概述 * a: 转换流概述 * OutputStreamWriter 是字符流通向字节流的桥梁:可使用指定的字符编码表,将要写入流 ...

  3. sql中exists和not exists的用法

    该文转载自:http://www.cnblogs.com/mytechblog/articles/2105785.html sql中exists,not exists的用法 exists : 强调的是 ...

  4. Linux adduser

  5. Powershell笔记之MVA课程

    很早之前看过MVA的Powershell课程,最近准备回顾一下,还是有一些意外的收获. <<快速入门 : PowerShell 3.0 高级工具和脚本>> 1. Invoke- ...

  6. Spring学习13-中IOC(工厂模式)和AOP(代理模式)的详细解释

    我们是在使用Spring框架的过程中,其实就是为了使用IOC,依赖注入,和AOP,面向切面编程,这两个是Spring的灵魂. 主要用到的设计模式有工厂模式和代理模式. IOC是工厂模式参考:设计模式- ...

  7. behavior

    http://www.css88.com/book/css/properties/only-ie/behavior.htm 语法: behavior:<url> | url(#objID) ...

  8. P2303 [SDOi2012]Longge的问题

    题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入输出格式 输入格式: 一 ...

  9. 在 Linux服务器中安装 Python 3.6

    一.服务器环境配置 在 CentOS 7 中安装 Python 之前,请确保系统中已经有了所有必要的开发依赖: # yum -y groupinstall development # yum -y i ...

  10. 【转】arm-none-linux-gnueabi-gcc下载

    arm-none-linux-gnueabi-gcc是 Codesourcery 公司(目前已经被Mentor收购)基于GCC推出的的ARM交叉编译工具.可用于交叉编译ARM系统中所有环节的代码,包括 ...