
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
image-scale
Advanced tools
Scale images to fit or fill any target container via two simple properties: scale and align.
Scale images to fit or fill any target container via two simple properties: scale and align.
This plugin is greatly inspired from Sproutcore SC.ImageView.
image-scale depends on jQuery. To use it, include this in your page :
<script src="jquery.js" type="text/javascript"></script>
<script src="image-scale.js" type="text/javascript"></script>
If you want to identify the images that you want to scale, you can add a class to them. In this example we are adding a class call scale.
You can also set the data-scale and data-align attributes directly to the images if you want to override the default setting.
<div class="image-container">
<img class="scale" data-scale="best-fit-down" data-align="center" src="img/example.jpg">
</div>
Now add this JavaScript code to your page :
$(function() {
$("img.scale").imageScale();
});
You're done.
Determines how the image will scale to fit within its containing space. Possible values:
Type: String
Default: best-fill
Align the image within its frame. Possible values:
Type: String
Default: center
A jQuery Object against which the image size will be calculated. If null, the parent of the image will be used.
Type: jQuery Object
Default: null
A boolean determining if the parent should hide its overflow.
Type: Boolean
Default: true
A duration in milliseconds determining how long the fadeIn animation will run when your image is scale for the firstTime.
Set it to 0 if you don't want any animation.
Type: Number or String
Default: 0
A boolean indicating if the image size should be rescaled when the window is resized.
The window size is checked using requestAnimationFrame for good performance.
Type: Boolean
Default: false
A function that will be call each time the receiver is scaled.
Example:
$images.imageScale({
didScale: function(firstTime, options) {
console.log('did scale img: ', this.element);
}
});
Type: Function
Parameters:
- firstTime {Boolean} true if the image was scale for the first time.
- options {Object} the options passed to the scale method.
A number indicating the debug level :
Type: Number
Default: 0
Main method. Used to scale the images.
When rescaleOnResize is set to true, this method is executed each time the
windows size changes.
If rescaleOnResize is set to false, you may want to call it manually. Here is an
example on how you should do it:
$image.imageScale('scale');
Removes the data for the element.
Here is an example on how you can call the destroy method:
$image.imageScale('destroy');
See it in action on our home page.
You can also check out the Sproutcore Automatic Image Scaling demo to understand the difference between all the different options.
Original Size: 3.91KB gzipped (13.99KB uncompressed)
Compiled Size: 1.8KB gzipped (4.42KB uncompressed)
Nicolas Badia
Copyright 2013-2015 GestiXi under The MIT License (MIT).
FAQs
Scale images to fit or fill any target container via two simple properties: scale and align.
The npm package image-scale receives a total of 53 weekly downloads. As such, image-scale popularity was classified as not popular.
We found that image-scale demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.