Skip to content

Instantly share code, notes, and snippets.

@EscApp2
Last active September 30, 2025 10:54
Show Gist options
  • Select an option

  • Save EscApp2/c6af69015267ce8fafb462661638d129 to your computer and use it in GitHub Desktop.

Select an option

Save EscApp2/c6af69015267ce8fafb462661638d129 to your computer and use it in GitHub Desktop.
Фиксируем плавающую панель сайта и панель админки Битрикса (Fixed Bitrix panel, bx-panel)
/*
https://gist.github.com/lekomtsev/d7fe3bfad8f42307fa2149e0816f3740
*/
var winWidth = function() {
var w = 0;
// IE
if (typeof( window.innerWidth ) != 'number') {
if (!(document.documentElement.clientWidth === 0)) {
// strict mode
w = document.documentElement.clientWidth;
} else {
// quirks mode
w = document.body.clientWidth;
}
} else {
// w3c
w = window.innerWidth;
}
return w;
};
/*
https://gist.github.com/lekomtsev/d7fe3bfad8f42307fa2149e0816f3740
*/
if(!!BX) {
BX.ready(function () {
if (BX.admin){
var arMyPanel = document.querySelectorAll(".header__info,.popup-history-description");
var BxPanel = BX.admin.panel,
FxPanel = function () {
let winWidthVal = winWidth();
arMyPanel.forEach(function (currentValue, currentIndex, listObj) {
let MyPanel = currentValue;
if(winWidthVal<768){
if (window.pageYOffset >= BxPanel.DIV.clientHeight && BxPanel.isFixed() === false) {
MyPanel.style.top = 0;
} else if (BxPanel.isFixed() === true) {
MyPanel.style.top = BxPanel.DIV.clientHeight + "px";
} else {
MyPanel.style.top = BxPanel.DIV.clientHeight - window.pageYOffset + "px";
}
}else{
MyPanel.style.top = 0;
}
});
};
if (!!arMyPanel && arMyPanel.length>0) {
FxPanel();
window.onresize = FxPanel;
window.onscroll = FxPanel;
BX.addCustomEvent('onTopPanelCollapse', BX.delegate(FxPanel, this));
BX.addCustomEvent('onTopPanelFix', BX.delegate(FxPanel, this));
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment