Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery .toggle() causing element to fade out on page load

Tags:

jquery

toggle

I'm trying to create an effect where when you click on an element it's size increases and when it's clicked again it goes back to the original size. For some reason when I'm using JQuery's toggle method it is causing the element (in this example a div) to shrink when the page loads. Here's a link to a JSFiddle I created: http://jsfiddle.net/6HNkF/ and here's my JavaScript:

    $(document).ready(function(){
        $('#mainImg').toggle(
            function(){
                $('#mainImg').animate({
                    width: '1000',
                    height: '1000'
                }, 500);
            },
            function(){
                $('#mainImg').animate({
                    width: '100',
                    height: '100'
                }, 500);
            }
        );
    });
like image 837
Tony Barsotti Avatar asked Dec 02 '25 02:12

Tony Barsotti


1 Answers

toggle as a click event was deprecated in 1.8. and finally removed in version 1.9.

.toggle(function, function, ... ) removed

This is the "click an element to run the specified functions" signature of .toggle(). It should not be confused with the "change the visibility of an element" of .toggle() which is not deprecated. The former is being removed to reduce confusion and improve the potential for modularity in the library. The jQuery Migrate plugin can be used to restore the functionality.

As you can see, it works with version 1.8.

like image 72
gdoron is supporting Monica Avatar answered Dec 04 '25 14:12

gdoron is supporting Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!