Skip to content

Anystretch is a jQuery plugin that allows you to add a dynamically-resized background image to any page or block level element. The image will stretch to fit the page/element, and will automatically resize as the window size changes. PLEASE NOTE: This is a fork of jQuery Backstretch by @srobbin.

License

GPL-2.0, MIT licenses found

Licenses found

GPL-2.0
GPL-LICENSE.txt
MIT
MIT-LICENSE.txt

ramazaneymur/jquery-anystretch

 
 

Repository files navigation

jQuery Anystretch

PLEASE NOTE: This is a fork of the original jQuery Backstretch by @srobbin. This version includes the ability to call Backstretch on any block level element and handles multiple instances.

Anystretch is a jQuery plugin that allows you to add a dynamically-resized background image to any page or block level element.
The image will stretch to fit the page/element, and will automatically resize as the window size changes.

Demo

An example is provided within this package. To see it in action go to: http://wearyoubelong.com

Options

centeredX

The ratio of the width/height of the image doesn’t always jive with the width/height of the window. This parameter controls whether or not we center the image on the X axis to account for the discrepancy. (type=Boolean, default=true)

centeredY

This parameter controls whether or not we center the image on the Y axis to account for the aforementioned discrepancy. (type=Boolean, default=true)

speed

This is the speed at which the image will fade in, after downloading is complete. Integers are accepted, as well as standard jQuery speed strings (slow, normal, fast). (type=Integer, default=0)

elPosition (only when not used on the body)

This is the css position given to the containing element when used on anything except the body. (type=String, default=relative)

Setup

Include the jQuery library and Anystretch plugin files in your webpage (preferably at the bottom of the page, before the closing BODY tag):

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="/jquery.anystretch.min.js"></script>

Note: The example above uses the Google hosted version of jQuery; there is also a jQuery source file included with this distribution, if you would like to host it yourself.

<script type="text/javascript">
  $.anystretch("/path/to/image.jpg", {speed: 150});
</script>

Want to change the image after Anystretch has been loaded? No problem, just call it again!

<script type="text/javascript">
  $.anystretch("/path/to/image.jpg", {speed: 150});
  
  // Perhaps you'd like to change the image on a button click
  $(".button").click(function() {
      $.anystretch("/path/to/next_image.jpg");
  });
</script>

If you require Anystretch to work on one or more elements inside the page, rather than the page itself, simply call it on the element:

<script type="text/javascript">
  $('#myDiv').anystretch("/path/to/image.jpg", {speed: 150});
</script>

Changelog

Version 1.0

  • This was forked from Backstretch (version 1.2)

About

Anystretch is a jQuery plugin that allows you to add a dynamically-resized background image to any page or block level element. The image will stretch to fit the page/element, and will automatically resize as the window size changes. PLEASE NOTE: This is a fork of jQuery Backstretch by @srobbin.

Resources

License

GPL-2.0, MIT licenses found

Licenses found

GPL-2.0
GPL-LICENSE.txt
MIT
MIT-LICENSE.txt

Stars

Watchers

Forks

Packages

No packages published