Side bar not freezing after script

Hi, Everyone

I’m using this script to freeze the left side bar so that i don’t need to scroll up when i need to view attachments.

However after applying this script i need to do Ctrl +Shift+R everytime, else the side bar starts overlapping.

Thank You

frappe.ui.form.on('Purchase Invoice', {
onload_post_render: function(frm) {
    if (window.innerWidth > 992) {
        var targetDiv = $(".col-lg-2.layout-side-section");
            position: 'fixed',
            zIndex: '1020',

            marginLeft: targetDiv.outerWidth()