Aarav
Aarav

Reputation: 73

how to write javascript value in translate3d css

I want to write my javascript value to translate a CSS class, however it is not working as I want. Can anyone tell me why?

var contentHeight = $('#mainContentHeight')[0].scrollHeight;
$('#menu').css({
  transform: "translateY(' + contentHeight + 'px)"
})

Upvotes: 1

Views: 3197

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337560

The issue is because you have mismatched quotes; " as the outer delimiters and ' around where you concatenate the variable. Try this:

var contentHeight = $('#mainContentHeight')[0].scrollHeight;
$('#menu').css({
  transform: 'translateY(' + contentHeight + 'px)'
})

Upvotes: 3

Related Questions