jquery coffeescript苹果手机主屏幕滑动触屏效果



79 315 106



特效描述:jquery coffeescript 手机主屏幕 滑动触屏效果,jquery框架与coffeescript结合制作iphone苹果手机的IOS手机界面主触屏手指划过屏幕整个界面图片左右滑动触屏效果。jquery下载。

代码结构

1. 引入JS

<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/touchable.js"></script>
<script type="text/javascript" src="js/coffee-script.js"></script>

2. HTML代码

<style type="text/css">
*{margin:0;padding:0;}
html{background-color:#161616;}
body{color:#fff;min-height:600px;font-family:Arial;}
a, a:visited {text-decoration:none;outline:none;color:#54a6de;}
a:hover{text-decoration:underline;}
/*----------------------------主屏幕-----------------------------*/
#homeScreen{width:810px;height:770px;padding:1px;margin:0 auto 30px;background:url('images/background.jpg') no-repeat left bottom;}
/* 面膜只显示在一个屏幕上的时间。使用溢出:隐藏 */
#mask{width:332px;height:380px;position:relative;overflow:hidden;margin:180px auto 0;}
#allScreens{height:100%;top:0;left:0;position:absolute;cursor:move;}
.screen{width:332px;float:left;}
#dock .dockicon,.screen .icon{float:left;width:60px;height:60px;background-repeat:no-repeat;margin:25px;position:relative;}
/* 下面的图标显示的标题属性:*/
.screen .icon:after{bottom:-25px;color:white;content:attr(title);font-size:12px;height:20px;left:-20px;overflow:hidden;position:absolute;text-align:center;white-space:nowrap;width:100px;text-shadow:0 0 3px #222;}#dock{height:70px;margin:60px auto;width:332px;}
/* 被告席上的图标得到下面这些细微的阴影 */
#dock .dockicon:after{border-radius:50px/10px;bottom:7px;box-shadow:0 5px 2px #000000;content:"";height:1px;position:absolute;width:58px;}
#indicators{text-align:center;list-style:none;}
#indicators li{border-radius:50%;display:inline-block;margin:7px;width:6px;height:6px;background-color:white;opacity:0.6;}
#indicators li.active{opacity:1;background-color:#00A2D6;box-shadow:0 0 3px #00A2D6, 0 0 1px #51CFF9 inset;}
</style>
<div id="homeScreen">
	<div id="mask">
		<div id="allScreens"></div>
	</div>
	<ul id="indicators"></ul>
	<div id="dock"></div>
</div>
<script type="text/coffeescript">
	# The Icon class. 
	class Icon
		# The constructor. The -> arrow signifies
		# a function definition.
		constructor: (@id, @title) ->
			# @ is synonymous for "this". The id and title parameters
			# of the construtor are automatically added as this.id and this.title
			# @markup holds the HTML of the icon. It is
			# transformed to this.markup behind the scenes.
			@markup = "<div class='icon' style='background-image:url(images/icons/#{@id}.png)'
						 title='#{@title}'></div>"
	# The DockIcon class inherits from Icon
	class DockIcon extends Icon
		constructor: (id, title)->
			# This calls the constructor if Icon
			super(id, title)
			# Changing the class name of the generated HTML 
			@markup = @markup.replace("class='icon'","class='dockicon'")
	# The Screen Class
	class Screen
		# Function arguments can have default parameters
		constructor: (icons = [])->
			@icons = icons
		attachIcons: (icons = [])->
			Array.prototype.push.apply(@icons, icons)
		generate: ->
			markup = []
			# Looping through the @icons array
			markup.push(icon.markup) for icon in @icons
			# The last line of every function is implicitly returned
			"<div class='screen'>#{markup.join('')}</div>"
	class Stage
		# The width of our "device" screen. This is 
		# basically the width of the #mask div.
		screenWidth: 332
		constructor: (icons)->
			@currentScreen = 0
			@screens = []
			# Calculating the number of screens
			# necessary to display all the icons
			num = Math.ceil(icons.length / 9)
			i = 0
			while num--
				# we pass a slice of the icons array
				s = new Screen(icons[i...i+9])
				# adding the screen to the local screens array
				@screens.push(s)
				i+=9
		# This method populates the passed element with HTML
		addScreensTo: (element)->
			@element = $(element)
			@element.width(@screens.length*@screenWidth)
			for screen in @screens
				@element.append(screen.generate())
		addIndicatorsTo: (elem)->
			# This method creates the small
			# circular indicatiors
			@ul = $(elem)
			for screen in @screens
				@ul.append('<li>')
			@ul.find('li:first').addClass('active');
		goTo: (screenNum)->
			# This method animates the allScreen div in
			# order to expose the needed screen in #mask
			if @element.is(':animated')
				return false
			# if this is the first or last screen,
			# run the end of scroll animation
			if @currentScreen == screenNum
				# Parallel assignment:
				[from, to] = ['+=15','-=15']
				if @currentScreen != 0
					[from, to] = [to, from]
				@element.animate( { marginLeft : from }, 150 )
						.animate( { marginLeft : to }, 150 )
			else
				# If everything is ok, animate the transition between the screens.
				# The fat arrow => preserves the context of "this"
				@element.animate( { marginLeft:-screenNum*@screenWidth }, => @currentScreen = screenNum )
				@ul.find('li').removeClass('active').eq(screenNum).addClass('active');
		next: ->
			toShow = @currentScreen+1
			# If there is no next screen, show
			# the current one
			if toShow == @screens.length
				toShow = @screens.length - 1
			@goTo(toShow)
		previous: ->
			toShow = @currentScreen-1
			# If there is no previous screen,
			# show the current one
			if toShow == -1
				toShow = 0
			@goTo(toShow)
	# This is equivalent to $('document').ready(function(){}):
	$ ->
		allIcons = [
			new Icon('Photos', 'Photo Gallery'), new Icon('Maps', 'Google Maps')
			new Icon('Chuzzle', 'Chuzzle'), new Icon('Safari', 'Safari')
			new Icon('Weather', 'Weather'), new Icon('nes', 'NES Emulator')
			new Icon('Calendar', 'Calendar'), new Icon('Clock', 'Clock')
			new Icon('BossPrefs', 'Boss Prefs'), new Icon('Chess', 'Chess')
			new Icon('Mail', 'Mail'), new Icon('Phone', 'Phone')
			new Icon('SMS', 'SMS Center'), new Icon('Camera', 'Camera')
			new Icon('iPod', 'iPod'), new Icon('Calculator', 'Calculator')
			new Icon('Music', 'Music'), new Icon('Poof', 'Poof')
			new Icon('Settings', 'Settings'), new Icon('YouTube', 'Youtube')
			new Icon('psx4all', 'PSx4All'), new Icon('VideoRecorder', 'Record Video')
			new Icon('Installer', 'Installer'), new Icon('Notes', 'Notes')
			new Icon('RagingThunder', 'RagingThunder'), new Icon('Stocks', 'Stocks')
			new Icon('genesis4iphone', 'Genesis'), new Icon('snes4iphone', 'SNES Emulator')
			new Icon('Calendar', 'Calendar'), new Icon('Clock', 'Clock')
			new Icon('Photos', 'Photo Gallery'), new Icon('Maps', 'Google Maps')
		]
		dockIcons = [
			new DockIcon('Camera', 'Camera')
			new DockIcon('iPod', 'iPod')
			new DockIcon('Calculator', 'Calculator')
		]
		allScreens = $('#allScreens')
		# Using the Touchable plugin to listen for
		# touch based events:
		allScreens.Touchable();
		# Creating a new stage object
		stage = new Stage(allIcons)
		stage.addScreensTo(allScreens)
		stage.addIndicatorsTo('#indicators')
		# Listening for the touchablemove event.
		# Notice the callback function
		allScreens.bind 'touchablemove', (e,touch)->	
			stage.next() if touch.currentDelta.x < -5
			stage.previous() if touch.currentDelta.x > 5
		# Adding the dock icons:
		dock = $('#dock')
		for icon in dockIcons
			dock.append(icon.markup)
</script>



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


热门标签: 图片叠加 图片层叠 图片翻转 图片旋转 图片延迟加载 图片延迟 图片加载 图片拖动 图片拖拽 图片淡出淡进 图片淡出 图片淡进 图片全屏 头像上传 图片上传 二维码 图片放大镜 h5图片动画 h5图标动画 html5图片动画 html5图标动画 带缩略图的幻灯片 地图 中国地图 世界地图 滑动 滑块 滑动门 触屏滑动 滑动插件 滑块插件 图片放大缩小 图片缩放 图片大小 图片放大 图片缩小 图片变大 图片变小 滚动切换 滚动条切换 滑动选项卡 滑动切换 图片广告 图片收缩展开 图片收缩 图片展开 纯图片轮播 图片轮播 图片滚动 图片滚动条 图片滑动 图片滑块 旋转木马 图片旋转木马 文字旋转木马 旋转木马插件 图片切换 图片选项卡 图标选项卡 自动滚动图片轮播 图标导航 图标菜单 选项卡切换 选项卡 切换 tab切换 页面切换 选项卡插件 切换插件 滑动手风琴 背景切换 大图切换 手风琴 水平手风琴 垂直手风琴 图片手风琴 文字手风琴 手风琴插件 图表 图片 图片插件 头像截图 图片滑动 图片滑块 选项卡自动切换 图片滑动 滑动图片

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

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

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