Jquery sticky banner follow on scroll

var $itemScript = $('.advertising-script-left-right');
if ($itemScript.offset()) {
    var stickyTop = [];
    $itemScript.each(function (index) {
        stickyTop.push($(this).offset().top);
    });
    $(window).scroll(function() {
        var windowTop = $(window).scrollTop();
        $itemScript.each(function (index) {
            if (stickyTop[index] < windowTop) {
                $(this).css({ position: 'fixed', top: 0 });
            } else {
                $(this).css('position', 'static');
            }
        });
    });
}