简体   繁体   中英

CoffeeScript: Need help converting function call with function as first argument into CoffeeScript

I'm trying to convert the following JavaScript into CoffeeScript:

$(window).afterResize( function() {

        var adjusted_window_height = $(window).height() - $('header').height() - $('footer').height();
        var vid_width = $('#section').width();
        var vid_height = adjusted_window_height - 20;
        var vid_margin = (adjusted_window_height - vid_height)/2;

        $('iframe.vimeo_player').css({
            width: vid_width,
            height: vid_height
        });

        if(vid_margin > 0){
            $('iframe.vimeo_player').css('margin-top',vid_margin+'px');
        }

        //Adjusts for scroll-bar follies 
        if($('iframe.vimeo_player').width() < $('#section').width()){
            $('iframe.vimeo_player').css({
                width: $('#section').width(),
                height: $(window).height() - $('header').height() - $('footer').height() - 20
            });
        }

}, true, 200 );

And the fact I'm passing in a function as the first argument of a function call is messing everything up. Can anyone point me in the right direction?

Replace function with -> as coffeescript requires. You'll also need to remove var statents

$(window).afterResize ->  
   foo()
, true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM