利用jQuery实现横向和纵向内容滚动插件Sly



50 197 66



特效描述:利用jQuery实现 横向和纵向 内容滚动 插件Sly,利用jQuery实现横向和纵向内容滚动插件Sly

代码结构

1. 引入CSS

<link href='http://fonts.googleapis.com/css?family=Exo:700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Exo:700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/style.css">

2. 引入JS

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.7.2.min.js"><\/script>')</script>
<script src="jquery.sly.js"></script>
<script src="js/vendor/plugins.js"></script>
<script src="js/main.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.7.2.min.js"><\/script>')</script>
<script src="jquery.sly.js"></script>
<script src="js/vendor/plugins.js"></script>
<script src="js/main.js"></script>

3. HTML代码

<!doctype html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<title></title>
	<meta name="description" content="jQuery plugin for one-directional scrolling with item based navigation support.">
	<meta name="viewport" content="width=device-width">
</head>
<body id="top">
	<div id="header">
		<div class="container">
			<h1>Sly</h1>
			<p>jQuery plugin for one-directional scrolling with item based navigation support</p>
			<div class="download">
				<h4>Download latest</h4>
				<a href="jquery.sly.js" class="left"><span>Development</span></a>
				<a href="jquery.sly.min.js" class="right"><span>Production</span></a>
			</div>
			<a href="//github.com/Darsain/sly" class="repo ir">Repository &amp; Documentation on Github</a>
			<ul id="nav" class="clearfix">
				<li><a href="#horizontal">Horizontal</a></li>
				<li><a href="#vertical">Vertical</a></li>
				<li><a href="#infinite">Infinite scroll</a></li>
			</ul>
		</div>
	</div>
	<div id="content">
	<div id="sections" class="container">
		<div id="horizontal">
			<div class="slyWrap example1">
				<div class="scrollbar">
					<div class="handle"></div>
				</div>
				<div class="sly" data-options='{ "horizontal": 1, "itemNav": "basic", "dragContent": 1, "startAt": 3, "scrollBy": 1 }'>
					<ul class="big cfix" data-items="30"></ul>
				</div>
				<ul class="pages"></ul>
				<div class="controls btn-toolbar">
					<div class="btn-group">
						<button class="btn prev">&laquo; prev</button>
						<button class="btn next">next &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn prevPage">&laquo; prevPage</button>
						<button class="btn nextPage">nextPage &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart">toStart</button>
						<button class="btn" data-action="toCenter">toCenter</button>
						<button class="btn" data-action="toEnd">toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart" data-arg="10"><strong>10</strong> toStart</button>
						<button class="btn" data-action="toCenter" data-arg="10"><strong>10</strong> toCenter</button>
						<button class="btn" data-action="toEnd" data-arg="10"><strong>10</strong> toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="add">Add item</button>
						<button class="btn" data-action="remove">Remove item</button>
					</div>
				</div>
<pre class="prettyprint lang-js">
$frame.sly({
	horizontal: 1,
	itemNav: "basic",
	dragContent: 1,
	startAt: 3,
	scrollBy: 1
});
</pre>
			</div>
			<hr>
			<div class="slyWrap example1">
				<div class="scrollbar">
					<div class="handle"></div>
				</div>
				<div class="sly" data-options='{ "horizontal": 1, "itemNav": "smart", "dragContent": 1, "startAt": 3, "scrollBy": 1 }'>
					<ul class="big cfix" data-items="30"></ul>
				</div>
				<ul class="pages"></ul>
				<div class="controls btn-toolbar">
					<div class="btn-group">
						<button class="btn prev">&laquo; prev</button>
						<button class="btn next">next &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn prevPage">&laquo; prevPage</button>
						<button class="btn nextPage">nextPage &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart">toStart</button>
						<button class="btn" data-action="toCenter">toCenter</button>
						<button class="btn" data-action="toEnd">toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart" data-arg="10"><strong>10</strong> toStart</button>
						<button class="btn" data-action="toCenter" data-arg="10"><strong>10</strong> toCenter</button>
						<button class="btn" data-action="toEnd" data-arg="10"><strong>10</strong> toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="add">Add item</button>
						<button class="btn" data-action="remove">Remove item</button>
					</div>
				</div>
<pre class="prettyprint lang-js">
$frame.sly({
	horizontal: 1,
	itemNav: "smart",
	dragContent: 1,
	startAt: 3,
	scrollBy: 1
});
</pre>
			</div>
			<hr>
			<div class="slyWrap example2">
				<div class="scrollbar">
					<div class="handle"></div>
				</div>
				<div class="sly" data-options='{ "horizontal": 1, "itemNav": "centered", "dragContent": 1, "scrollBy": 1 }'>
					<ul class="big cfix" data-items="30"></ul>
				</div>
				<ul class="pages"></ul>
				<div class="controls btn-toolbar">
					<div class="btn-group">
						<button class="btn prev">&laquo; prev</button>
						<button class="btn next">next &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn prevPage">&laquo; prevPage</button>
						<button class="btn nextPage">nextPage &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart">toStart</button>
						<button class="btn" data-action="toCenter">toCenter</button>
						<button class="btn" data-action="toEnd">toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toCenter" data-arg="10"><strong>10</strong> toCenter</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="add">Add item</button>
						<button class="btn" data-action="remove">Remove item</button>
					</div>
				</div>
<pre class="prettyprint lang-js">
$frame.sly({
	horizontal: 1,
	itemNav: "centered",
	dragContent: 1,
	scrollBy: 1
});
</pre>
			</div>
			<hr>
			<div class="slyWrap example2">
				<div class="scrollbar">
					<div class="handle"></div>
				</div>
				<div class="sly" data-options='{ "horizontal": 1, "itemNav": "forceCentered", "dragContent": 1, "scrollBy": 1, "easing": "easeOutBack" }'>
					<ul class="big cfix" data-items="10"></ul>
				</div>
				<ul class="pages"></ul>
				<div class="controls btn-toolbar">
					<div class="btn-group">
						<button class="btn prev">&laquo; prev</button>
						<button class="btn next">next &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn prevPage">&laquo; prevPage</button>
						<button class="btn nextPage">nextPage &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart">toStart</button>
						<button class="btn" data-action="toCenter">toCenter</button>
						<button class="btn" data-action="toEnd">toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toCenter" data-arg="5"><strong>5</strong> toCenter</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="add">Add item</button>
						<button class="btn" data-action="remove">Remove item</button>
					</div>
				</div>
<pre class="prettyprint lang-js">
$frame.sly({
	horizontal: 1,
	itemNav: "forceCentered",
	dragContent: 1,
	scrollBy: 1,
	easing: "easeOutBack" // with jQuery easing v1.3
});
</pre>
			</div>
			<hr>
			<div class="slyWrap example3">
				<div class="scrollbar">
					<div class="handle"></div>
				</div>
				<div class="sly" data-options='{ "horizontal": 1, "itemNav": "basic", "dragContent": 1, "scrollBy": 1, "cycleBy": "pages", "cycleInterval": 2000, "startPaused": 1 }'>
					<ul class="big cfix" data-items="10"></ul>
				</div>
				<ul class="pages"></ul>
				<div class="controls btn-toolbar">
					<div class="btn-group">
						<button class="btn btn-green" data-action="cycle">Start cycle</button>
						<button class="btn btn-green " data-action="cycle" data-arg="1">Pause</button>
					</div>
					<div class="btn-group">
						<button class="btn prevPage">&laquo; prevPage</button>
						<button class="btn nextPage">nextPage &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart">toStart</button>
						<button class="btn" data-action="toCenter">toCenter</button>
						<button class="btn" data-action="toEnd">toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart" data-arg="5"><strong>5</strong> toStart</button>
						<button class="btn" data-action="toCenter" data-arg="5"><strong>5</strong> toCenter</button>
						<button class="btn" data-action="toEnd" data-arg="5"><strong>5</strong> toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="add">Add item</button>
						<button class="btn" data-action="remove">Remove item</button>
					</div>
				</div>
<pre class="prettyprint lang-js">
$frame.sly({
	horizontal: 1,
	itemNav: "basic",
	dragContent: 1,
	scrollBy: 1,
	cycleBy: 'pages',
	cycleInterval: 2000,
	startPaused: 1
});
</pre>
			</div>
			<hr>
			<div class="slyWrap example4">
				<div class="sly" data-options='{ "horizontal": 1, "itemNav": "forceCentered", "cycleBy": "items", "cycleInterval": 2000 }'>
					<ul class="big cfix">
						<li>
							<h3>Lorem ipsum dolor</h3>
							<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
							Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
							pellentesque eu, pretium quis, sem.</p>
						</li>
						<li>
							<h3>Lorem ipsum dolor</h3>
							<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
							Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
							pellentesque eu, pretium quis, sem.</p>
						</li>
						<li>
							<h3>Lorem ipsum dolor</h3>
							<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
							Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
							pellentesque eu, pretium quis, sem.</p>
						</li>
						<li>
							<h3>Lorem ipsum dolor</h3>
							<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
							Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
							pellentesque eu, pretium quis, sem.</p>
						</li>
						<li>
							<h3>Lorem ipsum dolor</h3>
							<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
							Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
							pellentesque eu, pretium quis, sem.</p>
						</li>
						<li>
							<h3>Lorem ipsum dolor</h3>
							<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
							Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
							pellentesque eu, pretium quis, sem.</p>
						</li>
						<li>
							<h3>Lorem ipsum dolor</h3>
							<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
							Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
							pellentesque eu, pretium quis, sem.</p>
						</li>
					</ul>
				</div>
				<ul class="pages"></ul>
				<div class="controls btn-toolbar">
					<div class="btn-group">
						<button class="btn btn-green" data-action="cycle">Resume</button>
						<button class="btn btn-green" data-action="cycle" data-arg="1">Pause</button>
					</div>
					<div class="btn-group">
						<button class="btn prev">&laquo; prev</button>
						<button class="btn next">next &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn prevPage">&laquo; prevPage</button>
						<button class="btn nextPage">nextPage &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart">toStart</button>
						<button class="btn" data-action="toCenter">toCenter</button>
						<button class="btn" data-action="toEnd">toEnd</button>
					</div>
				</div>
<pre class="prettyprint lang-js">
$frame.sly({
	horizontal: 1,
	itemNav: 'forceCentered',
	cycleBy: 'items',
	cycleInterval: 2000
});
</pre>
			</div>
		</div><!--end:#horizontal-->
		<div id="vertical" class="clearfix">
			<div class="slyWrap example1">
				<div class="scrollbar">
					<div class="handle"></div>
				</div>
				<div class="sly" data-options='{ "itemNav": "smart", "dragContent": 1, "startAt": 10, "scrollBy": 1, "elasticBounds": 1 }'>
					<ul class="big cfix" data-items="30"></ul>
				</div>
				<ul class="pages"></ul>
				<div class="controls btn-toolbar">
					<div class="btn-group">
						<button class="btn prev">&laquo; prev</button>
						<button class="btn next">next &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn prevPage">&laquo; prevPage</button>
						<button class="btn nextPage">nextPage &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart">toStart</button>
						<button class="btn" data-action="toCenter">toCenter</button>
						<button class="btn" data-action="toEnd">toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="add">Add item</button>
						<button class="btn" data-action="remove">Remove item</button>
					</div>
				</div>
<pre class="prettyprint lang-js">
$frame.sly({
	itemNav: "smart",
	dragContent: 1,
	startAt: 10,
	scrollBy: 1,
	elasticBounds: 1
});
</pre>
			</div>
			<div class="slyWrap example2">
				<div class="scrollbar">
					<div class="handle"></div>
				</div>
				<div class="sly" data-options='{ "scrollBy": 100, "startAt": 200 }'>
					<div>
<h1>Lorem ipsum dolor</h1>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas.
Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.
<em>Aenean ultricies mi vitae est.</em> Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra.
Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt
condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. <a href="#">Donec non enim</a> in turpis pulvinar facilisis. Ut felis.</p>
<h2>Header Level 2</h2>
<ol>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ol>
<blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue.
Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus,
at luctus turpis elit sit amet quam. Vivamus pretium ornare est.</p></blockquote>
<h3>Header Level 3</h3>
<ul>
<li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
<li>Aliquam tincidunt mauris eu risus.</li>
</ul>
<pre>
#header h1 a {
display: block;
width: 300px;
height: 80px;
}
</pre>
<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>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>
<h4>Header Level 4</h4>
<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>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>
					</div>
				</div>
				<ul class="pages"></ul>
				<div class="controls btn-toolbar">
					<div class="btn-group">
						<button class="btn prevPage">&laquo; prevPage</button>
						<button class="btn nextPage">nextPage &raquo;</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart">toStart</button>
						<button class="btn" data-action="toCenter">toCenter</button>
						<button class="btn" data-action="toEnd">toEnd</button>
					</div>
					<div class="btn-group">
						<button class="btn" data-action="toStart" data-arg="h3"><strong>H3</strong> toStart</button>
						<button class="btn" data-action="toCenter" data-arg="h3"><strong>H3</strong> toCenter</button>
						<button class="btn" data-action="toEnd" data-arg="h3"><strong>H3</strong> toEnd</button>
					</div>
				</div>
<pre class="prettyprint lang-js">
$frame.sly({
	scrollBy: 100,
	startAt: 100
});
</pre>
			</div>
		</div><!--end:#vertical-->
		<div id="infinite">
			<div class="controlbar clearfix">
				<button class="btn btn-black fright" data-action="toStart">Back to top &uarr;</button>
				<button class="btn btn-red" data-action="reset">Reset to original state</button>
			</div>
			<hr>
			<div class="frameWrap">
				<div class="frame">
					<ul class="clearfix"></ul>
				</div>
				<div class="scrollbar">
					<div class="handle"></div>
				</div>
			</div>
<pre class="prettyprint lang-js">
$frame.on('sly:move', function( e, pos ){
	// If close to end, append new items
	if( pos.cur > pos.max - 100 ){
		populate( $ul, 10);
		$frame.sly('reload');
	}
}).sly({ itemNav: 'basic', scrollBy: 1 });
</pre>
		</div><!--end:#infinite-->
	</div><!--end:#sections-->
	</div><!--end:#content-->
<div style="text-align:center">
</div>
	<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
	<!-- scripts -->
	<!-- end scripts -->
</body>
</html>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 滚动导航菜单 导航切换 滚动切换 图片滚动 图片切换 文字滚动 文字切换 背景切换 图片文字滚动 手风琴 全屏滚动 选项卡自动切换 页面滚动 视频切换 列表切换 渐隐切换 全屏切换 切换按钮 缩放切换 滚动流动 滚动切换 滑动选项卡切换 自动滚动图片轮播 选项卡切换 滑动手风琴

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到