lazyload({defObj: "#page"}); var box = $("#page"); var scroll_ing = box.find("img"); var winw = $(window).width(); //设置高方法 function init_img_height() { winw = winw >= 640 ? 640 : winw; //判断横屏 scroll_ing.each(function() { var that = $(this); var h = that.attr("data-h"); if(h) { var nw_heihgt = Math.floor(h * winw / 640); that.attr("height", nw_heihgt); } }); } $(window).bind("resize", function() { //窗口改变 winw = $(window).width(); init_img_height(); init_top(); //重置顶部距离 }); init_img_height(); //设置图片高度 var $bx = $("#boxx").children(); var bx_top = []; //内容高度 var bx_topb = []; var tp_jian = parseInt($("#fixNav").height()); //需要减去的滚动高度 function init_top() { bx_top = []; bx_topb = []; $bx.each(function() { var f = Math.floor($(this).offset().top - tp_jian); bx_top.push(f); bx_topb.push(f + 20); }); bx_top.shift(); //删除第一个元素滚动判断 } init_top(); //获取区块顶部距离 var isf = false; var fxnav = $("#fixNav"); var fx_li = fxnav.children(); var nav_index = 0; var nav_top = fxnav.offset().top ; var reset_count = 0; //重新获取顶部距离 window.onscroll = function() { var sTop = document.documentElement.scrollTop + document.body.scrollTop; if(sTop >= nav_top) { if(!isf) { fxnav.addClass("fixd"); isf = true; } } else { if(isf) { fxnav.removeClass("fixd"); isf = false; } } daohang(sTop); } //计算当前导航index function daohang(t) { $.each(bx_top, function(a, b) { if(b >= t) { setNavon(a); return false; } }); } //改变导航的选中状态 function setNavon(i) { if(nav_index != i) { if(reset_count < 3) { init_top(); //重置高度,执行3次,防止未加载变化; reset_count++; } var nli = fx_li.eq(i); var bleft = Math.floor(nli.offset().left); var bw = Math.floor(nli.width()); // if(bleft + bw - winw > 0) { // document.getElementById("fixNav").scrollLeft = bw * i; // } else if(bleft < 0) { // document.getElementById("fixNav").scrollLeft = bleft; // } nli.addClass("action").siblings().removeClass("action"); nav_index = i; } } //点击导航 fxnav.delegate("li", "click", function() { var i = $(this).index(); if(i == nav_index) { return false; } setNavon(i); scrollBox(i); }); //滚动到指定区块 function scrollBox(i) { var a = bx_topb[i]; window.scrollTo(0, a); } // 添加顶部 function gtns(){ $('#gtn').toggle(); } function gx_btn(){ $('#gtn').hide(); }