A-A+
仿淘宝双11卖场专题两侧缩放导航效果源码
双11的时候,发现淘宝的活动页面的导航缩放展示效果做得非常有特色,所以连东西都没买就看别人的代码实现了,然后就把代码整理出来如下。
效果描述:
默认不显示两侧浮动导航,当页面滚动到一定位置时,两侧的导航内容以缩放显示的效果展示出来,当往上拖动滚动条至该位置临界点时两侧导航再以缩放显示的效果逐渐淡出显示!
实现思路:
2侧导航用postion:fixed定位,并默认visibility: hidden;当拖动滚动条至临界点位置时重新设置visibility: visible ,并用 css3 的transform 和 transition属性去实现缩放显示的效果。
关键代码是js根据滚动值去增删相应的class,以及相应class的transform 和 transition属性定义。
完整源码如下:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>测试页面</title>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
- <style>
- *{margin:0;padding:0;}
- body, td, input, textarea, select, button{color:#5f5f5f;font:12px/1.5 "Microsoft YaHei",Tahoma,Arial Geneva, sans-serif;}
- .demonstrate{width: 41%;height: 1000px;padding: 20px;margin: 10px auto;border: 1px #bbb solid;border-radius: 5px;}
- .description h3{color:#f00;padding-bottom:8px;}d
- .description p{padding-bottom:5px;}
- .description strong{color:#080; border-bottom:1px dotted;}
- .left-nav{width: 89px;height: 114px;position: fixed;left:50%;margin-left: -387px;bottom: 60px;z-index: 100;_position: absolute;_bottom: expression(60-documentElement.scrollTop);}
- .right-nav{width: 110px;height: 493px;position: fixed;left:50%;margin-left: 297px;top: 60px;z-index: 100;_position: absolute;_bottom: expression(60+documentElement.scrollTop);}
- .anim-nav{
- visibility: hidden;
- -webkit-transform: scale(0.01, 0.01);
- -moz-transform: scale(0.01, 0.01);
- -ms-transform: scale(0.01, 0.01);
- -o-transform: scale(0.01, 0.01);
- transform: scale(0.01, 0.01);
- -webkit-transition: all 500ms ease-in;
- -moz-transition: all 500ms linear;
- -ms-transition: all 500ms linear;
- -o-transition: all 500ms linear;
- transition: all 500ms linear;
- }
- .anim-nav-show{
- visibility: visible;
- -webkit-transform: scale(1, 1);
- -moz-transform: scale(1, 1);
- -ms-transform: scale(1, 1);
- -o-transform: scale(1, 1);
- transform: scale(1, 1);
- }
- </style>
- <script>
- $(function(){
- var temp=parseInt($(".test").css("bottom"));
- $(window).scroll(function(event) {
- $(".test").css({
- bottom:temp-$(window).scrollTop()
- })
- if($(window).scrollTop()>100){
- console.log("a");
- $(".anim-nav").hasClass('anim-nav-show')?"":$(".anim-nav").addClass('anim-nav-show');
- }else{
- $(".anim-nav").removeClass('anim-nav-show');
- }
- });
- })
- </script>
- </head>
- <body>
- <script>
- </script>
- <div class="demonstrate">
- <div class="description">
- <h2>跨域请求:JSONP获取JSON数据,含jq ajax实例</h2>
- <div class="txt">
- <h3>先说说JSONP是怎么产生的?</h3>
- <p>
- 1、一个众所周知的问题,Ajax直接请求普通文件存在跨域无权限访问的问题,甭管你是静态页面、动态网页、web服务、WCF,只要是跨域请求,一律不准;
- </p>
- </div>
- <div class="left-nav anim-nav">
- <img width="89" height="114" alt="天猫客户端随时随地双11" src="http://gtms01.alicdn.com/tps/i1/T1CpSFFmBhXXapY9za-89-114.png">
- </div>
- <div class="right-nav anim-nav">
- <img width="110" height="493" alt="天猫客户端随时随地双11" src="http://gtms01.alicdn.com/tps/i1/T1NzjEFi8cXXXOxZgs-110-493.png">
- </div>
- </div>
- </div>
- </body>
- </html>