Fixed menu problem with position when scrolling

Fixed menu problem with position when scrolling

I'm using this code for my fixed menu:

  1. $(document).ready(function () {
            function my_function() {
                var scroll_value = document.body.scrollTop;
                if (scroll_value > 0) {
                    $("#my_div").fadeOut(500);
                }
                else {
                    $("#my_div").fadeIn(500);
                }
                if (scroll_value >= 650) {
                    $('#sl_userNav').show('slide', { direction: 'up' }, 750);
                }
                else {
                    $('#sl_userNav').hide('slide', { direction: 'up' }, 750);
                }
                document.getElementById("sl_userNav").style.marginTop = scroll_value.toString() + "px";
            }
            setInterval(my_function, 5);
            my_function();
        });
jQuery 2.1.1 and jQuery UI 1.10.2 has been included.

I have 2 problems with that code:

- the first one - "#my_div" disappear but not in a smooth way (fadeIn/fadeOut doesn't work)
- the second - my fixed menu jump up and down on fast scrolling