oleinresurs (27 Сентябрь 2016 - 17:49) писал:
Как зафиксировать .header-middle при прокрутке?
В конце forall.js добавил код:
/*
Sticky-kit v1.0.4 | WTFPL | Leaf Corcoran 2014 | http://leafo.net
*/
(function(){var t,i;t=this.jQuery,i=t(window),t.fn.stick_in_parent=function(o){var s,n,e,r,c,a,l;for(null==o&&(o={}),r=o.sticky_class,s=o.inner_scrolling,e=o.parent,n=o.offset_top,null==n&&(n=0),null==e&&(e=void 0),null==s&&(s=!0),null==r&&(r="is_stuck"),c=function(o,c,a,l,p,d,f){var u,h,k,g,v,m,y,_,b,w;if(!o.data("sticky_kit")){if(o.data("sticky_kit",!0),m=o.parent(),null!=e&&(m=m.closest(e)),!m.length)throw"failed to find stick parent";if(u=k=!1,b=t("<div />"),b.css("position",o.css("position")),y=function(){var t,i;return t=parseInt(m.css("border-top-width"),10),i=parseInt(m.css("padding-top"),10),c=parseInt(m.css("padding-bottom"),10),a=m.offset().top+t+i,l=m.height(),t=k?(k=!1,u=!1,o.insertAfter(B).css({position:"",top:"",width:"",bottom:""}).removeClass(r),b.detach(),!0):void 0,p=o.offset().top-parseInt(o.css("margin-top"),10)-n,d=o.outerHeight(!0),f=o.css("float"),b.css({width:o.outerWidth(!0),height:d,display:o.css("display"),"vertical-align":o.css("vertical-align"),"float":f}),t?w():void 0},y(),d!==l)return g=void 0,v=n,w=function(){var t,e,h,y;return h=i.scrollTop(),null!=g&&(e=h-g),g=h,k?(y=h+d+v>l+a,u&&!y&&(u=!1,o.css({position:"fixed",bottom:"",top:v}).trigger("sticky_kit:unbottom")),p>h&&(k=!1,v=n,"left"!==f&&"right"!==f||o.insertAfter(B),b.detach(),t={position:"",width:"",top:""},o.css(t).removeClass(r).trigger("sticky_kit:unstick")),s&&(t=i.height(),d>t&&!u&&(v-=e,v=Math.max(t-d,v),v=Math.min(n,v),k&&o.css({top:v+"px"})))):h>p&&(k=!0,t={position:"fixed",top:v},t.width="border-box"===o.css("box-sizing")?o.outerWidth()+"px":o.width()+"px",o.css(t).addClass(r).after(B),"left"!==f&&"right"!==f||b.append(o),o.trigger("sticky_kit:stick")),k&&(null==y&&(y=h+d+v>l+a),!u&&y)?(u=!0,"static"===m.css("position")&&m.css({position:"relative"}),o.css({position:"absolute",bottom:c,top:"auto"}).trigger("sticky_kit:bottom")):void 0},_=function(){return y(),w()},h=function(){return i.off("scroll",w),t(document.body).off("sticky_kit:recalc",_),o.off("sticky_kit:detach",h),o.removeData("sticky_kit"),o.css({position:"",bottom:"",top:""}),m.position("position",""),k?(o.insertAfter(B).removeClass(r),b.remove()):void 0},i.on("touchmove",w),i.on("scroll",w),i.on("resize",_),t(document.body).on("sticky_kit:recalc",_),o.on("sticky_kit:detach",h),setTimeout(w,0)}},a=0,l=this.length;l>a;a++)o=this[a],c(t(o));return this}}).call(this);
В конце main.js добавил Вам код:
// Функция фиксации шапки
jQuery(document).ready(function($){
if($('.header-middle')){
$('.header-middle').stick_in_parent({
sticky_class: 'keep-menu'
});
}
});
В конце main.css добавил код:
.header-middle.keep-menu {z-index: 100;background: fadeOut(#000000, 20%);position: fixed !important;top: 0px !important;}
Проверьте, пожалуйста.