1、页面切换、组件切换

jQuery全屏滚动插件 fullPage.js

官网:http://www.uedsc.com/fullpage.html

引入文件

	<script src="../js/jquery-3.1.1.min.js"></script>
	<script src="../js/jquery.fullPage.js"></script>
	<script src="../js/jquery-ui.js"></script>
	

使用传入对象

$(function(){
    $('#fullpage').fullpage({
        'verticalCentered': false,
        'css3': true,
        'sectionsColor': ['#254875', '#00FF00', '#254587', '#695684'],
        anchors: ['page1', 'page2', 'page3', 'page4'],
        'navigation': true,
        'navigationPosition': 'right',
        'navigationTooltips': ['fullPage.js', 'Powerful', 'Amazing', 'Simple']
    })
})

组件切换,fullpage页面切换事件与当前页面结合起来

$(function(){
			$("#h5").fullpage({
				'sectionsColor': ['#254875', '#00FF00', '#254587', '#695684'],
				//当当前页面离开时,事件回调
				onLeave:function( index,nextIndex,direction){//当前位置,下一个位置,方向
					$("#h5").find(".page").eq(index-1).trigger("onLeave")
				},
				//第二个页面载入完成
				afterLoad:function(anchorLink ,index){ //锚点名称 ,index  
					$("#h5").find(".page").eq(index-1).trigger("onLoad")
				}
			})
			
			//为Dom元素作事件
				$('.page').on("onLeave",function(){
					console.log($(this).attr("id"),"==>>","onLeave")
				})
				
				$('.page').on("onLoad",function(){
					console.log($(this).attr("id"),"==>>","onLeave")
				})
		})
	</script>

触发所有页面事件

触发第一个页面事件

组件与component结合

triggerHandler不光可以阻止事件冒泡,而且只会影响匹配到的第一个元素,所以用triggerHandler和return false的结果一样,原理不同。

注意:DOM事件的小循环传播---无限循环(子元素与父元素监听相同事件,父元素触发事件执行子元素,子元素触发事件,又会被父元素监听到,陷入无限循环)

 

<script>
$(function(){
			$("#h5").fullpage({
				'sectionsColor': ['#254875', '#00FF00', '#254587', '#695684'],
				//当当前页面离开时,事件回调
				onLeave:function( index,nextIndex,direction){//当前位置,下一个位置,方向
					$("#h5").find(".page").eq(index-1).trigger("onLeave");
				},
				//第二个页面载入完成
				afterLoad:function(anchorLink ,index){ //锚点名称 ,index  
					$("#h5").find(".page").eq(index-1).trigger("onLoad");
				}
			})
			
			//为Dom元素作事件
				$('.page').on("onLeave",function(){ //当前页面触发onLeave事件,component组件执行onLeave事件
					console.log($(this).attr("id"),"==>>","onLeave");
					$(this).find(".component").triggerHandler("onLeave");//阻止事件向上传播方法一
				})
				
				$('.page').on("onLoad",function(){
					console.log($(this).attr("id"),"==>>","onLoad");
					$(this).find(".component").trigger("onLoad");
				})
				
				$('.component').on("onLoad",function(){
					$(this).fadeIn(); //渐隐渐现
					return false; //事件执行完不向上传播 //阻止事件向上传播方法二
				})
				
				$('.component').on("onLeave",function(){
					$(this).fadeOut(); //渐隐渐现
				})
		})
	</script>
	<body>
		<!--
        	作者:offline
        	时间:2017-03-03
        	描述:用于验证fullpage.js切换页面,以及内容组织结构可用,组建能够进行动画
       -->
	<div id="h5">
		<div class="page section" id="page-1">
			<div class="component logo"> logo</div>
			<div class="component slogan"> slogan</div>
		</div>
		<div class="page section" id="page-2">
			<div class="component desc">desc</div>
		</div>
		<div class="page section" id="page-3">
			<div class="component desc">bar 柱状图</div>
		</div>
	</div>
	</body>

 

转载于:https://my.oschina.net/u/2991733/blog/853320

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TwoPanels是管理俩个页面切换的控件,俩个页面间既可以水平排列也可垂直排列。俩个页面都是Fragment,中间有个slider,负责控制俩个页面切换。通常他把左页面或垂直排列的上页面都叫左(left)页面, 把右页面或垂直排列的下页面都叫右(right)页面。项目地址:https://github.com/DesarrolloAntonio/TwoPanels 效果图:如何使用让你的Activity继承自TwoPanelsBaseActivitypublic class MainActivity extends TwoPanelsBaseActivity {2. 设置左、右页面以及设置参数setBaseOrientation(LinearLayout.HORIZONTAL);//设置俩个页面的排列方式,水平还是垂直 MyRightFragment mRightFragment = new MyRightFragment();//右页面,这个Fragment你需要自定义 MyLeftFragment mLeftFragment = new MyLeftFragment(); getFragmentManager().beginTransaction().add(R.id.right, mRightFragment).commit();//将页面的Fragment绑定到控件上 getFragmentManager().beginTransaction().add(R.id.left, mLeftFragment).commit();方法使用方法名说明setSlidersDrawables(int verticalDrawable, int horizontalDrawable)Set de drawables for the slider in horizontal and vertical like this example: setSlidersDrawables(R.drawable.slider_vertical, R.drawable.slider_horizontal)设置slider(左、右页面中间部分的)的图标,分为垂直的和水平的图标setSliderSize(int size)设置slider的宽度switchSliderVisitility();以动画方式切换setBaseOrientation(int orientation)Set the orientation of the panels with the values LinearLayout.VERTICAL or LinearLayout.HORIZONTAL, default is LinearLayout.HORIZONTAL.设置排列方式,水平的还是垂直的slideFragmentsToRight()Slide the fragments to the right with an animation.隐藏掉右页面或下页面,相当于点击俩次右箭头slideFragmentsToLeft()Slide the fragments to the left with an animation隐藏掉左页面或上页面,相当于点击俩次左箭头.showTwoFragments()Show two panels in the screen.让俩个页面都显示,一般是调用了hideRight()、hideLeft后让俩个页面同时显示hideRight()Hide the right panel and show the left panel in full screen.隐藏右页面hideLeft()Hide the left panel and show the right panel in full screen.隐藏左页面
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值