Run javascript function when the page loads

77 Views Asked by At

I have a JS example downloaded and I wish to ask you if is any chance to start on window load.

<script>
window.onload = function() {
    $.fn.rotate.serialize();

    var gear1 = document.getElementById('gear1');
    var gear2 = document.getElementById('gear2');
    $('#centerpiece').on('mouseenter',function() {
        if(!gear1.isRotating && !gear2.isRotating) {
            gear1.isRotating = true;
            gear2.isRotating = true;
            $(gear1).rotate(360,{speed:140},function() {
                gear1.isRotating = true;
                $(this).rotate('reset');
            });
            $(gear2).rotate(360,{speed:110},function() {
                gear2.isRotating = true;
                $(this).rotate('reset');
            });
        }
    });
};
</script>
1

There are 1 best solutions below

7
On BEST ANSWER

Removed window.onload and now it runs without mouseover.

if(!gear1.isRotating && !gear2.isRotating) {
        gear1.isRotating = true;
        gear2.isRotating = true;
        $('#gear1').rotate(360,{speed:140},function() {
            gear1.isRotating = true;
            $('#gear1').rotate('reset');
        });
        $('#gear2').rotate(360,{speed:110},function() {
            gear2.isRotating = true;
            $('#gear2').rotate('reset');
        });
    }