Created
June 20, 2018 07:45
-
-
Save elricco/ca06b641740bdfd64f4299f4c95747c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this is specific for sonata admin - but can be tweaked for other purposes | |
//was to lazy to write a class | |
$(function () { | |
window.setTimeout(function () { | |
var elementExists = !!document.getElementsByClassName('.tablesaw-bar'); | |
if(elementExists) { | |
makeTablesawBarSticky(); | |
} | |
}, 100); | |
function makeTablesawBarSticky() { | |
var distance = $('.tablesaw-overflow').offset().top - 122, $window = $(window); | |
$window.scroll(function() { | |
if ( $window.scrollTop() >= distance ) { | |
//make bar sticky when tablehead reaches offset | |
$('.tablesaw-bar').css({ | |
'position': 'fixed', | |
'top': '102px', | |
'background': '#f5f5f5', | |
'width': $('.content-wrapper').outerWidth() + 'px', | |
'margin': '0 -15px', | |
'padding': '0 15px', | |
'border' : '1px solid #CCC', | |
'z-index': '999' | |
}); | |
} | |
else { | |
//reset css and unstick bar | |
$('.tablesaw-bar').css({ | |
'position': '', | |
'top': '', | |
'background': '', | |
'width': '', | |
'margin': '', | |
'padding': '', | |
'border' : '', | |
'z-index': '' | |
}); | |
} | |
}); | |
window.addEventListener("resize",function() { | |
if ( $window.scrollTop() >= distance ) { | |
window.setTimeout(function () { | |
//resize bar when window resizes | |
$('.tablesaw-bar').css('width', $('.content-wrapper').outerWidth() + 'px'); | |
}, 360); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment