Skip to content

@sbp /fiddle.html
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Resize SVG images
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/7/77/Kirshhoff-example.svg" alt="Kirshhoff-example" class="resizable">
</div>
$(function() {
$('.resizable').each(function() {
$(this).load(function() {
var img = $(this);
var parent = img.parent();
parent.css('position', 'relative');
var div = $('<div></div>');
img.before(div);
var width = img.width();
div.width(width);
div.css({
height: '64px',
background: '#ccc',
position: 'absolute',
top: '0',
left: '0',
opacity: '0',
});
div.hover(function() { div.css('opacity', '.5') },
function() { div.css('opacity', '0') });
img.hover(function() { div.css('opacity', '.5') },
function() { div.css('opacity', '0') });
var span = false;
function create_span() {
var offset = false;
span = $('<span><img src="http://upload.wikimedia.org/wikipedia/commons/f/f2/Sideways_double_arrow_yellow.svg" width="64" alt="resize"></span>');
div.append(span);
span.css({
margin: '0',
position: 'absolute',
right: '16px',
cursor: 'pointer'
});
span.draggable({
axis: 'x',
start: function(event, ui) {
if (!offset) { offset = ui.offset.left; }
},
drag: function(event, ui) {
img.width(width + (ui.offset.left - offset));
div.width(width + (ui.offset.left - offset));
}});
}
create_span();
div.click(function() {
div.width(width);
img.width(width);
span.remove();
create_span();
});
})
})
})
resources:
- https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.