Skip to content

Instantly share code, notes, and snippets.

@daslicht
Created September 6, 2012 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daslicht/3656944 to your computer and use it in GitHub Desktop.
Save daslicht/3656944 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; 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">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script>
<script type="text/javascript" src="js/jquery.mousewheel.js"></script>
<title>iScroll demo: Snap to element</title>
<script type="text/javascript" src="js/iscroll.js"></script>
<script type="text/javascript">
var myScroll;
function loaded() {
myScroll = new iScroll('wrapper', {
snap: 'li',
momentum: false,
hScrollbar: false,
vScrollbar: false,
onScrollEnd: function ()
{
//$('#currentPage').html( myScroll.currPageX+1);
// document.querySelector('#indicator > li.active').className = '';
// document.querySelector('#indicator > li:nth-child(' + (this.currPageX+1) + ')').className = 'active';
console.log('onScrollEnd ' );
/*if(myScroll.x=== myScroll.maxScrollX ){//-1800
loadContent();
}*/
}
});
console.log("loaded" );
}
document.addEventListener('DOMContentLoaded', loaded, false);
</script>
<style type="text/css" media="all">
body,ul,li {
padding:0;
margin:0;
border:0;
}
body {
font-size:12px;
-webkit-user-select:none;
-webkit-text-size-adjust:none;
font-family:helvetica;
}
#header {
position:absolute;
top:0; left:0;
width:100%;
height:45px;
line-height:45px;
background-image:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #fe96c9), color-stop(0.05, #d51875), color-stop(1, #7b0a2e));
background-image:-moz-linear-gradient(top, #fe96c9, #d51875 5%, #7b0a2e);
background-image:-o-linear-gradient(top, #fe96c9, #d51875 5%, #7b0a2e);
padding:0;
color:#eee;
font-size:20px;
text-align:center;
}
#header a {
color:#f3f3f3;
text-decoration:none;
font-weight:bold;
text-shadow:0 -1px 0 rgba(0,0,0,0.5);
}
#wrapper {
position:absolute; z-index:1;
top:45px; bottom:0; left:0;
width:250px;
height:368px;
overflow:auto;
background:#eee;
}
#scroller {
width:250px;
float:left;
padding:0;
}
#scroller ul {
list-style:none;
display:block;
float:left;
width:100%;
height:100%;
padding:0;
margin:0;
border:1px solid #aaa;
/*overflow: hidden;*/
}
#scroller li {
display:block;
float:left;
width:250px;
height:50px;
/*line-height:78px;*/
text-align:center;
border:1px solid #aaa;
background:#ccc;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="scroller">
<ul id="thelist">
<li>cell 1</li>
<li>cell 2</li>
<li>cell 3</li>
<li>cell 4 </li>
<li>cell 5 </li>
<li>cell 6</li>
<li>cell 7</li>
<li>cell 8</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
<li>cell</li>
</ul>
</div>
</div>
<script>
/**** MOUSE WHEEL ******/
$(function() {
//$('#userAgent').html(navigator.userAgent);
$('#wrapper').mousewheel(function(event, delta, deltaX, deltaY)
{
//mouse= true;
console.log("myScroll.currPageX", myScroll.currPageY );
if (delta > 0){
//o = '#test2: up ('+delta+')';
// myScroll.scrollToPage('next');
//$('#currentPage').html( myScroll.currPageY+1);
//console.log( delta );
}else if (delta < 0){
//o = '#test2: down ('+delta+')';
// myScroll.scrollToPage('prev', 0);
//$('#currentPage').html( myScroll.currPageY+1);
// console.log( delta );
}
// prevent default*
return false;
});
});
</script>
<div id="prev" onclick="myScroll.scrollToPage('prev');return false">&larr; prev</div>
<div id="next" onclick="myScroll.scrollToPage('next');return false">next &rarr;</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment