Transfer animation code (script) to external file

I made the animation code which works correctly, but when I move this code to an external file, the code doesn’t work.

$(document).ready( function() {
            var item_width = $('#slides li').outerWidth(true);
            var old_left = parseInt($('#slides ul').css('left'));
            var top_indent = old_left - item_width;
            var right_indent = item_width + old_left;
            var left = 0;

            var animateBox = function () {
                left = (left) ? 0 : (right_indent / 3);

                $('#slides ul').animate({
                    'top': top_indent,
                    'left': left

                }, 1500, function () {
                    $('#slides li:last').after($('#slides li:first'));
                    $('#slides ul').css({ 'top': 0 });
                    setTimeout(function () { animateBox(); }, 0);
                });
            }
            animateBox();
        });

I tried this too but it still didn’t work.

$(function () {

       // code

        });