// 搜索框效果 var searchmodel = function (btnid, formid, val) { var show = false; var postdate = function () { if ($(val).val() == '') { return false; } else { $(formid).submit(); } }; var search = function () { $(btnid).click(function () { $(val).addclass('show'); if (show) { postdate(); } if (!show) { show = true; } }) }; return { search: search } }; var searchdemo = new searchmodel('#search', '#search_form', '#search_box'); searchdemo.search(); //头部导航栏效果 $('.head-nav-ul li').mouseover(function () { $(this).addclass('moveactive').siblings().removeclass('moveactive'); $('.nav-child-nav').hide(); $(this).find('.nav-child-nav').show(); }).mouseout(function () { $(this).find('.nav-child-nav').hide(); }) $('.head-nav-ul').mouseleave(function () { $('.head-nav-ul li').removeclass('moveactive'); }) /** * 解析url参数 * @example ?id=12345&a=b * @return object {id:12345,a:b} */ function urlparse() { var url = window.location.search; var obj = {}; var reg = /[?&][^?&]+=[^?&]+/g; var arr = url.match(reg); // ['?id=12345', '&a=b'] if (arr) { arr.foreach(function (item) { var temparr = item.substring(1).split('='); var key = decodeuricomponent(temparr[0]); var val = decodeuricomponent(temparr[1]); obj[key] = val; }); } return obj; }; // 顶部导航固定 var divtop = $('.head-nav').offset(); $(window).scroll(function () { console.log('divtop.top:' + divtop.top); var doctop = $(document).scrolltop(); console.log('doctop:' + doctop); if (divtop.top <= doctop) { $('.head-nav').addclass('active') } else { $('.head-nav').removeclass('active'); } })