Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.05 KB | None | 0 0
  1. $window.on('resize', function () {
  2.     adjustGameContainerSize($iframe, payload.gameWidthRatio)
  3. });
  4.  
  5. function adjustGameContainerSize($container, ratio){
  6.     var containerHeight = getGameContainerHeight();
  7.  
  8.     // Adjusting iframe size
  9.     if (ratio > 0) {
  10.         var containerWidth = getGameContainerWidth(containerHeight, ratio);
  11.         var iframeMaximumWidth = $window.width();
  12.         // Checking whether the computed with is within the boundary
  13.         if (containerWidth > iframeMaximumWidth) {
  14.             // Reduce the height of the iframe
  15.             containerHeight = containerHeight * (iframeMaximumWidth / containerWidth);
  16.             // JUST then overwrite the iframe width
  17.             containerWidth = iframeMaximumWidth;
  18.         }
  19.         $container.width(containerWidth);
  20.     }
  21.     $container.height(containerHeight);
  22. }
  23.  
  24. function getGameContainerHeight(){
  25.     var iframeExtraMargin = 20;
  26.     return $window.height() - $infoBar.height() - iframeExtraMargin;
  27. }
  28.  
  29. function getGameContainerWidth(height, ratio){
  30.     return height * ratio;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement