(function ($, w) { var winhei = $(w).height(); var loadfn = function () { var $conlis = $('[_load]'); $conlis.each(function (i, v) { var scrolltop = $(w).scrolltop(); var $v = $(v); if ($conlis.filter('_load') == 0) $(w).off('scroll.z'); if (winhei + scrolltop > $v.offset().top) { $v.addclass('active'); $(this).removeattr('_load'); } }) }; $(w).on('scroll.z load', loadfn); })(jquery, window); $(function () { var screenheight = document.documentelement.clientheight; //fixed nav bind on jquery $.fn.navfixed = function () { var $_this = $(this), $_this_prev_marginbottom = parseint($_this.prev().css("margin-bottom").substring(0, $_this.prev().css("margin-bottom").length - 2)), $_this_next_margintop = parseint($_this.next().css("margin-top").substring(0, $_this.next().css("margin-top").length - 2)), _topposition = $(document).scrolltop(), _navposition = $_this.prev().find('img').height(); _if(); $(document).scroll(function () { _topposition = $(document).scrolltop(); _if(); }); $(window).resize(function () { _navposition = $_this.prev().find('img').height(); _if(); }); function _if() { var width = $(window).width(); // console.log(_topposition,_navposition) if (_navposition > 21 && _topposition >= _navposition) { $_this.css("position", "fixed"); if (width <= 1024) { $_this.css("top", "0"); } $_this.next().css("margin-top", $_this_prev_marginbottom + $_this.outerheight() + $_this_next_margintop + "px"); } else { $_this.css("position", "relative"); if (width <= 1024) { $_this.css("top", "0"); } $_this.next().css("margin-top", $_this_next_margintop + "px"); } } } $(".form input").focus(function () { $(this).css("border-bottom", "1px solid #147cd2"); }); $(".form input").blur(function () { $(this).css("border-bottom", "1px solid rgba(255, 255, 255, 0.5)"); }); $(".home.banner").height(screenheight); $('.nav-button').click(function () { $(this).toggleclass('active'); $('header nav').slidetoggle(); $('.search').removeclass('mobile'); $('.mobile-search-list').removeclass('active'); }); $(".searchbtn").on("click",function(){ $(".header .right").addclass("active"); $(".searchbox").addclass("active"); $(".searchinput input").focus(); }) $(".searchinput input").on("blur",function(){ $(".header .right").removeclass("active"); $(".searchbox").removeclass("active"); }) // mobile $(".nav-button").on("click",function(){ $(".menucontainer").slidetoggle() }) window.addeventlistener("scroll",function(){ var scrollheight = document.documentelement.scrolltop | document.body.scrolltop; if(scrollheight>document.documentelement.offsetheight){ $(".totop").stop().animate({bottom:"0.75rem"},500); }else{ $(".totop").stop().animate({bottom:"-0.75rem"},500); } }) $(".totop").on("click",function(){ $("html,body").animate({scrolltop:0}, 500); }) }); var link_url="http://www.yantangmilk.com";