Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save basz/2877030 to your computer and use it in GitHub Desktop.
Save basz/2877030 to your computer and use it in GitHub Desktop.
Breaking the HTML5 Video Aspect Ratio
# 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})")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment