Guest User

Untitled

a guest
May 25th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. jQuery.fn.resizeWithWindow = function(options) {
  2. var settings = $.extend($.fn.resizeWithWindow.defaults, options),
  3. element = $(this);
  4.  
  5. adjustSize(element);
  6. $(window).resize(function() {
  7. adjustSize(element);
  8. });
  9.  
  10. function adjustSize(targets) {
  11. return targets.each(function() {
  12.  
  13. var target = {
  14. height: $(this).height(),
  15. width: $(this).width()
  16. },
  17. browser = {
  18. height: $(window).height(),
  19. width: $(window).width()
  20. },
  21. ratio = {
  22. height: target.height / browser.height,
  23. width: target.width / browser.width
  24. };
  25.  
  26. if (ratio.height > ratio.width) {
  27. $(this).css({
  28. 'width': 'auto',
  29. 'height': '100%'
  30. });
  31. settings.container
  32. .height(browser.height)
  33. .width($(this).width() + settings.offset_width);
  34. } else {
  35. settings.container
  36. .css('width', 'auto')
  37. .height($(this).height());
  38. $(this)
  39. .css({
  40. 'width': '100%',
  41. 'height': 'auto'
  42. });
  43. }
  44.  
  45. return false;
  46. });
  47. }
  48.  
  49. };
  50.  
  51. jQuery.fn.resizeWithWindow.defaults = {
  52. container: $(this).parent(),
  53. offset_width: 0
  54. };
Add Comment
Please, Sign In to add comment