SVG移动端图标导航页面切换
XML/HTML Code
- <div class="phone">
- <div class="page">Home</div>
- <nav>
- <div class="wave-wrap">
- <svg version="1.1" id="wave" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 119 26">
- <path class="path" d="M120.8,26C98.1,26,86.4,0,60.4,0C35.9,0,21.1,26,0.5,26H120.8z">
- </svg>
- </div>
- <ul class="list-wrap">
- <li data-color="#eccc68" title="Home">
- <i class="icon ion-ios-home"></i>
- </li>
- <li data-color="#ff6b81" title="Profile">
- <i class="icon ion-ios-person"></i>
- </li>
- <li data-color="#7bed9f" title="Get a beer!">
- <i class="icon ion-ios-beer"></i>
- </li>
- <li data-color="#70a1ff" title="Files">
- <i class="icon ion-ios-folder-open"></i>
- </li>
- <li data-color="#dfe4ea" title="Settings">
- <i class="icon ion-ios-settings"></i>
- </li>
- </ul>
- </nav>
- </div>
JavaScript Code
- // set the first nav item as active
- var dis = $(".list-wrap li").eq(0);
- // align the wave
- align(dis);
- // align the wave on click
- $(".list-wrap li").click(function(){
- dis = $(this);
- align(dis);
- });
- function align(dis){
- // get index of item
- var index = dis.index() + 1;
- // add active class to the new item
- $(".list-wrap li").removeClass("active");
- dis.delay(100).queue(function() {
- dis.addClass('active').dequeue();
- });
- // move the wave
- var left = index * 80 - 98;
- $("#wave").css('left', left);
- // ▼ this is not necessary for the navigation ▼
- // set the background color
- var color = dis.data('color');
- $("body").css('background', color);
- // set the text
- $(".page").text(dis.attr("title"));
- }
原文地址:http://www.freejs.net/article_daohangcaidan_774.html