Created
September 15, 2011 13:24
-
-
Save jimjeffers/1219207 to your computer and use it in GitHub Desktop.
Breaking the HTML5 Video Aspect Ratio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Just an example. | |
# @video is a direct reference to a '<video>' element. | |
# $() is assuming jQuery is being used in this example. | |
@video.addEventListener("loadedmetadata", (event) => | |
actualRatio = @video.videoWidth/@video.videoHeight | |
targetRatio = $(@video).width()/$(@video).height() | |
adjustmentRatio = targetRatio/actualRatio | |
$(@video).css("-webkit-transform","scaleX(#{adjustmentRatio})") | |
) |
What do you mean by "direct reference"? I'd assumed that I'd just need to replace @video with whatever I'd use to reference the element, say
I assume he means $('.videoelem').get(0) if you are using jQuery because he's referring to the dom element itself, not the jQuery object. or...
$('.videoelem').get(0).addEventListener... to put it in context
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dude you are awesome saved me a bunch of time.