Win8风格的Web启动界面

开发 前端
主要用到jquery.animation.easing.js 和jquery.mousewheel.min.js 两个jQuery插件。数据源 source.js;核心脚本 script.js......

主要用到jquery.animation.easing.js 和jquery.mousewheel.min.js 两个jQuery插件。

页面布局

HTML

  1. View Code   
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml"> 
  4.     <head> 
  5.         <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
  6.         <link rel="stylesheet" type="text/css" href="lib/style.css"/> 
  7.         <link rel="shortcut icon" href="favicon.png"/> 
  8.         <script type="text/javascript" src="lib/jquery-1.6.1.min.js"></script> 
  9.         <script type="text/javascript" src="lib/jquery.animation.easing.js"></script> 
  10.         <script type="text/javascript" src="lib/jquery.mousewheel.min.js"></script> 
  11.         <script type="text/javascript" src="source.js"></script> 
  12.         <script type="text/javascript" src="lib/script.js"></script> 
  13.           
  14.         <title>New tab</title> 
  15.     </head> 
  16.     <body> 
  17.         <div id="place"> 
  18.             <div id="name1"></div> 
  19.             <div id="wrapper1"> 
  20.                 <div id="thumb1-1"></div> 
  21.                 <div id="thumb1-2"></div> 
  22.                 <div id="thumb1-3"></div> 
  23.                 <div id="thumb1-4"></div> 
  24.                 <div id="thumb1-5"></div> 
  25.                 <div id="thumb1-6"></div> 
  26.                 <div id="thumb1-7"></div> 
  27.                 <div id="thumb1-8"></div> 
  28.                 <div id="thumb1-9"></div> 
  29.                 <div id="thumb1-10"></div> 
  30.                 <div id="thumb1-11"></div> 
  31.                 <div id="thumb1-12"></div> 
  32.               
  33.                 <form action="" method="get"> 
  34.                     <input type="text" name="q" value="" /><button type="submit"></button> 
  35.                     <div id="engines1"> 
  36.                         <div id="google1"></div> 
  37.                         <div id="bing1"></div> 
  38.                         <div id="yahoo1"></div> 
  39.                         <div id="wikipedia1"></div> 
  40.                     </div> 
  41.                     <div id="search-engine1"></div> 
  42.                 </form> 
  43.             </div><!-- end wrapper1 --> 
  44.             <div id="button1to2"></div> 
  45.             <div id="button2to1"></div> 
  46.             <div id="name2"></div> 
  47.             <div id="wrapper2"> 
  48.                 <div id="thumb2-1"></div> 
  49.                 <div id="thumb2-2"></div> 
  50.                 <div id="thumb2-3"></div> 
  51.                 <div id="thumb2-4"></div> 
  52.                 <div id="thumb2-5"></div> 
  53.                 <div id="thumb2-6"></div> 
  54.                 <div id="thumb2-7"></div> 
  55.                 <div id="thumb2-8"></div> 
  56.                 <div id="thumb2-9"></div> 
  57.                 <div id="thumb2-10"></div> 
  58.                 <div id="thumb2-11"></div> 
  59.                 <div id="thumb2-12"></div> 
  60.               
  61.                 <form action="" method="get"> 
  62.                     <input type="text" name="q" value="" placeholder="" /><button type="submit"></button> 
  63.                     <div id="engines2"> 
  64.                         <div id="google2"></div> 
  65.                         <div id="bing2"></div> 
  66.                         <div id="yahoo2"></div> 
  67.                         <div id="wikipedia2"></div> 
  68.                     </div> 
  69.                     <div id="search-engine2"></div> 
  70.                 </form> 
  71.             </div><!-- end wrapper2 --> 
  72.             <div id="button2to3"></div> 
  73.             <div id="button3to2"></div> 
  74.             <div id="name3"></div> 
  75.             <div id="wrapper3"> 
  76.                 <div id="thumb3-1"></div> 
  77.                 <div id="thumb3-2"></div> 
  78.                 <div id="thumb3-3"></div> 
  79.                 <div id="thumb3-4"></div> 
  80.                 <div id="thumb3-5"></div> 
  81.                 <div id="thumb3-6"></div> 
  82.                 <div id="thumb3-7"></div> 
  83.                 <div id="thumb3-8"></div> 
  84.                 <div id="thumb3-9"></div> 
  85.                 <div id="thumb3-10"></div> 
  86.                 <div id="thumb3-11"></div> 
  87.                 <div id="thumb3-12"></div> 
  88.               
  89.                 <form action="" method="get"> 
  90.                     <input type="text" name="q" value="" placeholder="" /><button type="submit"></button> 
  91.                     <div id="engines3"> 
  92.                         <div id="google3"></div> 
  93.                         <div id="bing3"></div> 
  94.                         <div id="yahoo3"></div> 
  95.                         <div id="wikipedia3"></div> 
  96.                     </div> 
  97.                     <div id="search-engine3"></div> 
  98.                 </form> 
  99.             </div><!-- end wrapper3 --> 
  100.         </div><!-- end place --> 
  101.     </body> 
  102. </html> 

#p#

数据源 source.js

  1. View Code   
  2.  
  3. var hoverEffect = true// set true for hover effect, set false for no hover effect  
  4.  
  5. var searchEngine = 'google'// default search engine - set google for google search, bing for bing search, yahoo for yahoo search  
  6.  
  7. var numberOfScreens = 3; // set number of screens (1 or 2 or 3)  
  8.    
  9. var blockName = new Array(); // set names of blocks  
  10. blockName[1] = 'Most used';  
  11. blockName[2] = 'Social';  
  12. blockName[3] = 'News & fun';  
  13.  
  14. var bookmark = new Array();  
  15. bookmark[0] = new Array();  
  16. bookmark[1] = new Array();  
  17. bookmark[2] = new Array();  
  18.  
  19. // set your bookmarks here: (If you do not fill 'thumb' for thumbnail will be used title)  
  20. // FIRST BLOCK  
  21. bookmark[0][0] = {  
  22.     'title':'YouTube',  
  23.     'url':'http://youtube.com',  
  24.     'thumb':'youtube.png' 
  25. };  
  26. bookmark[0][1] = {  
  27.     'title':'Yahoo',  
  28.     'url':'http://yahoo.com',  
  29.     'thumb':'yahoo.png' 
  30. };  
  31. bookmark[0][2] = {  
  32.     'title':'Grooveshark',  
  33.     'url':'http://grooveshark.com',  
  34.     'thumb':'grooveshark.png' 
  35. };  
  36. bookmark[0][3] = {  
  37.     'title':'last.fm',  
  38.     'url':'http://www.last.fm/',  
  39.     'thumb':'lastfm.png' 
  40. };  
  41. bookmark[0][4] = {  
  42.     'title':'twitter',  
  43.     'url':'http://twitter.com',  
  44.     'thumb':'twitter.png' 
  45. };  
  46. bookmark[0][5] = {  
  47.     'title':'google',  
  48.     'url':'http://google.com',  
  49.     'thumb':'google.png' 
  50. };  
  51. bookmark[0][6] = {  
  52.     'title':'facebook',  
  53.     'url':'http://facebook.com',  
  54.     'thumb':'facebook.png' 
  55. };  
  56. bookmark[0][7] = {  
  57.     'title':'BBC news',  
  58.     'url':'http://www.bbc.co.uk/news/',  
  59.     'thumb':'bbcnews.png' 
  60. };  
  61. bookmark[0][8] = {  
  62.     'title':'CNN',  
  63.     'url':'http://www.cnn.com',  
  64.     'thumb':'cnn.png' 
  65. };  
  66. bookmark[0][9] = {  
  67.     'title':'deviantART',  
  68.     'url':'http://deviantart.com',  
  69.     'thumb':'deviantart.png' 
  70. };  
  71. bookmark[0][10] = {  
  72.     'title':'wikipedia',  
  73.     'url':'http://wikipedia.org',  
  74.     'thumb':'wikipedia.png' 
  75. };  
  76. bookmark[0][11] = {  
  77.     'title':'iTunes',  
  78.     'url':'http://www.apple.com/itunes/',  
  79.     'thumb':'itunes.png' 
  80. };  
  81. // end of FIRST BLOCK  
  82. // SECOND BLOCK  
  83. bookmark[1][0] = {  
  84.     'title':'linkedin',  
  85.     'url':'http://www.linkedin.com/',  
  86.     'thumb':'linkedin.png' 
  87. };  
  88. bookmark[1][1] = {  
  89.     'title':'digg',  
  90.     'url':'http://digg.com/',  
  91.     'thumb':'digg.png' 
  92. };  
  93. bookmark[1][2] = {  
  94.     'title':'flickr',  
  95.     'url':'http://www.flickr.com/',  
  96.     'thumb':'flickr.png' 
  97. };  
  98. bookmark[1][3] = {  
  99.     'title':'msn',  
  100.     'url':'http://www.msn.com/',  
  101.     'thumb':'msn.png' 
  102. };  
  103. bookmark[1][4] = {  
  104.     'title':'reddit',  
  105.     'url':'http://www.reddit.com/',  
  106.     'thumb':'reddit.png' 
  107. };  
  108. bookmark[1][5] = {  
  109.     'title':'skype',  
  110.     'url':'http://www.skype.com/',  
  111.     'thumb':'skype.png' 
  112. };  
  113. bookmark[1][6] = {  
  114.     'title':'technorati',  
  115.     'url':'http://technorati.com',  
  116.     'thumb':'technorati.png' 
  117. };  
  118. bookmark[1][7] = {  
  119.     'title':'delicious',  
  120.     'url':'http://www.delicious.com/',  
  121.     'thumb':'delicious.png' 
  122. };  
  123. bookmark[1][8] = {  
  124.     'title':'MySpace',  
  125.     'url':'http://www.myspace.com/',  
  126.     'thumb':'myspace.png' 
  127. };  
  128. bookmark[1][9] = {  
  129.     'title':'orkut',  
  130.     'url':'http://www.orkut.com/',  
  131.     'thumb':'orkut.png' 
  132. };  
  133. bookmark[1][10] = {  
  134.     'title':'tumblr',  
  135.     'url':'http://www.tumblr.com/',  
  136.     'thumb':'tumblr.png' 
  137. };  
  138. bookmark[1][11] = {  
  139.     'title':'StumbleUpon',  
  140.     'url':'http://www.stumbleupon.com/',  
  141.     'thumb':'stumbleupon.png' 
  142. };  
  143. //end of SECOND BLOCK  
  144. // THIRD BLOCK  
  145. bookmark[2][0] = {  
  146.     'title':'eurosport',  
  147.     'url':'http://www.eurosport.com/',  
  148.     'thumb':'eurosport.png' 
  149. };  
  150. bookmark[2][1] = {  
  151.     'title':'amazon',  
  152.     'url':'http://www.amazon.com/',  
  153.     'thumb':'amazon.png' 
  154. };  
  155. bookmark[2][2] = {  
  156.     'title':'eBay',  
  157.     'url':'http://www.ebay.com/',  
  158.     'thumb':'ebay.png' 
  159. };  
  160. bookmark[2][3] = {  
  161.     'title':'IMDb',  
  162.     'url':'http://www.imdb.com/',  
  163.     'thumb':'imdb.png' 
  164. };  
  165. bookmark[2][4] = {  
  166.     'title':'vimeo',  
  167.     'url':'http://vimeo.com',  
  168.     'thumb':'vimeo.png' 
  169. };  
  170. bookmark[2][5] = {  
  171.     'title':'lifehacker',  
  172.     'url':'http://lifehacker.com/',  
  173.     'thumb':'lifehacker.png' 
  174. };  
  175. bookmark[2][6] = {  
  176.     'title':'engadged',  
  177.     'url':'http://www.engadget.com/',  
  178.     'thumb':'engadget.png' 
  179. };  
  180. bookmark[2][7] = {  
  181.     'title':'zune',  
  182.     'url':'http://www.zune.net/',  
  183.     'thumb':'zune.png' 
  184. };  
  185. bookmark[2][8] = {  
  186.     'title':'dropbox',  
  187.     'url':'http://www.dropbox.com/',  
  188.     'thumb':'dropbox.png' 
  189. };  
  190. bookmark[2][9] = {  
  191.     'title':'National Geographic',  
  192.     'url':'http://www.nationalgeographic.com/',  
  193.     'thumb':'natgeo.png' 
  194. };  
  195. bookmark[2][10] = {  
  196.     'title':'CBC news',  
  197.     'url':'http://www.cbc.ca/news/',  
  198.     'thumb':'cbcnews.png' 
  199. };  
  200. bookmark[2][11] = {  
  201.     'title':'weather.com',  
  202.     'url':'http://www.weather.com/',  
  203.     'thumb':'weather.png' 
  204. }; 

#p#

核心脚本 script.js

  1. View Code   
  2.  
  3. $(document).ready(function(){  
  4.     var num = numberOfScreens;  
  5.  
  6.     for(var i=1;i<=num;i++){  
  7.         $('#name'+i).html(blockName[i]);  
  8.     }  
  9.       
  10.     if(hoverEffect){  
  11.         for(i=1;i<=num;i++){  
  12.             $('<style>#wrapper'+i+' div.site:hover{border: 1px #fff solid;box-shadow: 0px 0px 5px #fff;margin-left:4px;margin-top:4px;}</style>').appendTo('head');  
  13.         };  
  14.     };  
  15.       
  16.     if(searchEngine=='google'){  
  17.         search='http://www.google.com/search';  
  18.     }  
  19.     else if(searchEngine=='bing'){  
  20.         search='http://www.bing.com/search';  
  21.     }  
  22.     else if(searchEngine=='yahoo'){  
  23.         search='http://search.yahoo.com/bin/search';  
  24.     }  
  25.     else{  
  26.         search='http://www.google.com/search';  
  27.         searchEngine='google';  
  28.     };  
  29.  
  30.     $('form').attr('action',search);  
  31.     $('#search-engine').css('background','#fff url(img/'+searchEngine+'.png) center center no-repeat');  
  32.       
  33.     var windowWidth = $(window).width();  
  34.     var windowHeight = $(window).height();  
  35.     var left1 = Math.floor((windowWidth - 960)/2);  
  36.     var left2 = left1 - 1040;  
  37.     var left3 = left1 - 2080;  
  38.     var wrapperTop = Math.floor((windowHeight - 480)/2)-60;  
  39.       
  40.     $('#place').css({'left':left1,'top':wrapperTop});  
  41.     var wrapperPos = 1;  
  42.     $('#wrapper1 input:text').focus();  
  43.     var animDone = true;  
  44.       
  45.     function anim1to2(){  
  46.         $('#wrapper1 input:text').focusout();  
  47.         animDone = false;  
  48.         $('#place').animate({  
  49.             left: left2,  
  50.         },1000,'circEaseOut',function() {  
  51.             $('#wrapper2 input:text').focus();  
  52.             animDone = true;  
  53.             wrapperPos = 2;  
  54.         });  
  55.         $('#button1to2').hide();              
  56.         $('#button2to1').show();  
  57.         if(num>2){  
  58.             $('#button2to3').show();  
  59.             $('#button3to2').hide();  
  60.         };  
  61.     };  
  62.       
  63.     function anim2to1(){  
  64.         $('#wrapper2 input:text').focusout();  
  65.         animDone = false;  
  66.         $('#place').animate({  
  67.             left: left1  
  68.         },1000,'circEaseOut',function() {  
  69.             $('#wrapper1 input:text').focus();  
  70.             animDone = true;  
  71.             wrapperPos = 1;  
  72.         });  
  73.         $('#button1to2').show();              
  74.         $('#button2to1').hide();  
  75.         if(num>2){  
  76.             $('#button2to3').hide();  
  77.             $('#button3to2').hide();  
  78.         };          
  79.     };  
  80.       
  81.     function anim2to3(){  
  82.         $('#wrapper2 input:text').focusout();  
  83.         animDone = false;  
  84.         $('#place').animate({  
  85.             left: left3  
  86.         },1000,'circEaseOut',function() {  
  87.             $('#wrapper3 input:text').focus();  
  88.             animDone = true;  
  89.             wrapperPos = 3;  
  90.         });  
  91.         $('#button1to2').hide();  
  92.         $('#button3to2').show();  
  93.         $('#button2to1').hide();  
  94.         $('#button2to3').hide();      
  95.     };  
  96.       
  97.     function anim3to2(){  
  98.         $('#wrapper3 input:text').focusout();  
  99.         animDone = false;  
  100.         $('#place').animate({  
  101.             left: left2  
  102.         },1000,'circEaseOut',function() {  
  103.             $('#wrapper2 input:text').focus();  
  104.             animDone = true;  
  105.             wrapperPos = 2;  
  106.         });  
  107.         $('#button1to2').hide();  
  108.         $('#button3to2').hide();  
  109.         $('#button2to1').show();  
  110.         $('#button2to3').show();              
  111.     };  
  112.       
  113.     if(num>1){  
  114.         $('#button1to2').click(function(){  
  115.             anim1to2();  
  116.         });  
  117.           
  118.         $('#button2to1').click(function(){  
  119.             anim2to1();  
  120.         });  
  121.           
  122.         if(num>2){  
  123.             $('#button2to3').click(function(){  
  124.                 anim2to3();  
  125.             });  
  126.               
  127.             $('#button3to2').click(function(){  
  128.                 anim3to2();  
  129.             });  
  130.         };  
  131.     };  
  132.  
  133.     $(document).bind('keydown',function(event){   
  134.         if(event.keyCode == '39' || event.keyCode == '37'){  
  135.             event.preventDefault();  
  136.         }  
  137.         if(event.which=='39' && animDone){  
  138.               
  139.             if(wrapperPos==1 && num>1){  
  140.                 anim1to2();  
  141.             };  
  142.             if(wrapperPos==2 && num>2){  
  143.                 anim2to3();  
  144.             };  
  145.         };  
  146.         if(event.which=='37' && animDone){  
  147.               
  148.             if(wrapperPos==3){  
  149.                 anim3to2();  
  150.             };  
  151.             if(wrapperPos==2){  
  152.                 anim2to1();  
  153.             };              
  154.         };  
  155.     });   
  156.  
  157.     $(document).mousewheel(function(event, delta) {  
  158.         if (delta > 0 && animDone){  
  159.             if(wrapperPos==3){  
  160.                 anim3to2();  
  161.             };  
  162.             if(wrapperPos==2){  
  163.                 anim2to1();  
  164.             };  
  165.         }  
  166.         else if (delta < 0 && animDone){  
  167.             if(wrapperPos==1 && num>1){  
  168.                 anim1to2();  
  169.             };  
  170.             if(wrapperPos==2 && num>2){  
  171.                 anim2to3();  
  172.             };  
  173.         };          
  174.         event.preventDefault();          
  175.     });  
  176.  
  177.     var j=0;  
  178.     for (j=0; j <=(num-1); j++) {          
  179.         if(bookmark[j]==nullcontinue;  
  180.         for(i=0;i<=11;i++){              
  181.             if(bookmark[j][i]==nullcontinue;  
  182.             var title = bookmark[j][i]['title'];  
  183.             var url = bookmark[j][i]['url'];  
  184.             var thumb = bookmark[j][i]['thumb'];  
  185.             if(thumb==''){  
  186.                 $('#thumb'+(j+1)+'-'+(i+1)).html('<img id="net" src="img/net.png" /><a href="'+url+'"><div class="title">'+title+'</div></a>');  
  187.             }  
  188.             else{  
  189.                 $('#thumb'+(j+1)+'-'+(i+1)).html('<a href="'+url+'"><img src="http://developer.51cto.com/exp/code/img/thumb/'+thumb+'" /></a>');  
  190.             }  
  191.         };  
  192.     };  
  193.       
  194.     $('#search-engine').click(function() {  
  195.         $('#engines').fadeToggle('fast','circEaseOut');  
  196.         $('#wrapper1 input:text').css('background','#fff');  
  197.     });  
  198.       
  199.     $('#google').click(function() {  
  200.         $('#wrapper1 form').attr('action','https://www.google.com/search');  
  201.         $('#engines').fadeToggle('fast','circEaseOut');  
  202.         $('#wrapper1 #search-engine').css('background','#fff url(img/google.png) center center no-repeat');  
  203.         $('#wrapper1 input:hidden').detach();  
  204.         $('#wrapper1 input:first').attr('name','q');  
  205.         $('#wrapper1 input:text').focus();  
  206.     });  
  207.     ……  
  208. }); 

源码下载:Win8_style_web_start_page_and_config.rar

改造后的示例:http://www.mayixue.com/demo/win8page/index.htm

示例代码:Win8StartScreen.rar

在这里感谢原作者,记录下来留个念想。

【编辑推荐】

  1. HTML 5应用普及,浏览器取代应用商店
  2. Facebook发布HTML 5应用中心
  3. 开发HTML5跨平台游戏相关经验
  4. HTML 5将成香饽饽APP要何去何从
  5. 通过WHATWG看HTML 5的未来
责任编辑:张伟 来源: MAYIXUE的博客
相关推荐

2013-12-13 09:36:45

Windows 8Firefox

2012-03-09 09:50:19

Win8系统恢复功能

2012-06-01 09:28:43

Windows 8Metro

2012-06-29 13:06:38

Win8Metro

2014-07-08 09:18:27

WIFIWin8

2011-09-22 13:49:39

2012-06-14 10:04:39

2013-12-12 16:09:06

微软Windows 8

2011-10-31 09:52:00

Canonical红帽安全启动

2012-06-07 16:44:36

win8 RP版评测

2012-09-10 09:14:13

2014-08-21 14:49:27

Win8微软

2013-12-03 09:35:35

Windows 8.1Windows 8

2013-03-22 14:27:52

iOSWin8UI设计

2012-11-13 10:57:09

Win8网络接入

2012-03-14 09:25:35

Windows 8休眠选项

2012-05-16 12:46:55

Win8WindowsXP

2012-03-28 16:37:05

2013-12-16 13:32:33

Windows 8.2Windows 8

2013-12-06 10:11:48

Windows 8Windows 7Windows 8.1
点赞
收藏

51CTO技术栈公众号