这是内容面板的基本结构。
1 2 3 4 5 6 7 8 9 10 | < div class = "grid-container blue" > < div class = "shadow-box" > < div class = "content" > </ div > < div class = "shadows" > < div class = "shadow top" ></ div > < div class = "shadow bottom" ></ div > </ div > </ div > </ div > |
这是css的影子。创建滚动阴影效果2阴影元素,一个定位框右上角的内容,和其他定位在左下角。他们一起grid-container类动画,他们是有界的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | .shadow-box { display : block ; position : relative ; z-index : 1 ; width : 300px ; height : 400px ; } .shadow-box .content { position : relative ; z-index : 1 ; width : inherit; height : inherit; background-color : #fff ; } .shadow-box .shadows { -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)" ; filter: alpha(opacity= 30 ); -moz-opacity: 0.3 ; -khtml-opacity: 0.3 ; opacity: 0.3 ; } .shadow-box .shadow { position : absolute ; z-index : -1 ; left : 0 ; bottom : 0 ; width : 100% ; height : 200% ; background-color : #444 ; -webkit-transform: rotate( -45 deg); -moz-transform: rotate( -45 deg); -ms-transform: rotate( -45 deg); -o-transform: rotate( -45 deg); transform: rotate( -45 deg); } .shadow-box .shadow. top { right : 0 ; top : 0 ; -webkit-transform-origin: 100% 0 ; transform-origin: 100% 0 ; } .shadow-box .shadow. bottom { -webkit-transform-origin: 0 0 ; transform-origin: 0 0 ; right : 0 ; top : 100% ; } |
滚动角计算影子。基本上,每个shadow-box将计算百分比多少滚动在当前视图的窗口。你可以改变影子开始的角度,一旦你完全滚动过去它将结束,通过改变
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | startingRotate和endingRotate变量。 // scrolling shadow effect function updateParallax() { $( ".grid-container" ).each( function () { var height = $( this ).height(); var bottom = $( this ).offset().top + height; var top = $( this ).offset().top; var windowHeight = $(window).height(); var scrollTop = $(window).scrollTop() + windowHeight; var fromTop = $(window).scrollTop() - top; if ((bottom > $(window).scrollTop()) && (top < scrollTop)) { var percent = ((scrollTop - top) / (height + windowHeight)); var startingRotate = -80; // Starting angle of shadow var endingRotate = -15; // Ending angle of shadow var shadowRotate = (startingRotate - endingRotate) * (1 - percent) + endingRotate; if (shadowRotate < startingRotate) { shadowRotate = startingRotate } else if (shadowRotate > 0) { shadowRotate = 0; } $( this ).find( '.shadow-box .shadow' ).css({ '-webkit-transform' : 'rotate(' + shadowRotate + 'deg)' }); $( this ).find( '.shadow-box .shadow' ).css({ '-moz-transform' : 'rotate(' + shadowRotate + 'deg)' }); $( this ).find( '.shadow-box .shadow' ).css({ '-ms-transform' : 'rotate(' + shadowRotate + 'deg)' }); $( this ).find( '.shadow-box .shadow' ).css({ '-o-transform' : 'rotate(' + shadowRotate + 'deg)' }); $( this ).find( '.shadow-box .shadow' ).css({ 'transform' : 'rotate(' + shadowRotate + 'deg)' }); } }); } updateParallax(); $(window).scroll( function () { updateParallax(); }); |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com