How to rewrite JS with CoffeeScript

424
May 06, 2017, at 11:48 PM

I have such code in JS:

$('.slider-for').find('img').each(function(){
  var imgClass = (this.width/this.height > 1) ? 'wide' : 'tall';
  $(this).addClass(imgClass);
})

And need to rewrite it in Coffee. There is what I've got:

$('.slider-cover-photo img').each ->
  imgClass = if $(this).width / $(this).height > 1 then 'wide' else 'tall'
  $(this).addClass imgClass

this here is a correct element. But when I try to get its width or height, its value is 0 ($(this).width = 0)

Rent Charter Buses Company
READ ALSO
Github pages not loading W3.CSS?

Github pages not loading W3.CSS?

I am trying to create a github page using the css stylesheet from W3CSS

533
Closing an 'accordian' <div> but forcing a 'top' return

Closing an 'accordian' <div> but forcing a 'top' return

I have an 'accordion' embedded in a PHP while loop

257
column resizing without restricting the other columns - uigrid

column resizing without restricting the other columns - uigrid

I saw uigrid tutorial for column resizing

318
Page refresh printing raw html code instead of output

Page refresh printing raw html code instead of output

I've created a chrome extension for my college websiteHere is the small code:

308