Reputation: 163
I am working on a PHP script which contains a page that has SVG inside it. What I want to do is to use the Jquery Resize feature. I have tried this on a div and it's working fine but when I want to use it to resize the image inside the SVG it doesn't work. Here is the code:
<div class="resize">
doiud
</div>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="800" height="420" id="svg">
<image height="120" width="120" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://designpieces.com/wp-content/uploads/2013/04/chrome.png" ></image></svg>
The Jquery Code :
$('.resize').resizable({
ghost: true
});
$('image').resizable({
ghost: true
});
Upvotes: 5
Views: 4266
Reputation: 71
Thanks for the tips. I was able to wrap my svg object within a div. And then I used the resize ui event size to set the CSS on the object.
HTML
<div id="divVirtualKeyboard" style="display: none; position: absolute; top: 200px; left: 100px">
<div>
<object id="canvasKeyboard" data="static/EmulatorKeyboard.svg" type="image/svg+xml" width="376" height="214" style="pointer-events:none;"></object>
</div>
</div>
JS
div.resizable(
{
aspectRatio: 376 / 214,
resize: function (event, ui) {
div.find('object').css('width', ui.size.width)
div.find('object').css('height', ui.size.height)
}
});
Upvotes: 0
Reputation: 194
Try this one jsfiddle
Wrapped on div to image.
html
<div class="resize">
resize helper
</div>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="800" height="420" id="svg">
<image height="120" width="120" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://designpieces.com/wp-content/uploads/2013/04/chrome.png" ></image>
</svg>
script
$('.resize').resizable({
ghost: true,
resize: function( event, ui ) {
var width = ui.size.width;
var height = ui.size.height;
$('image').attr('width',width);
$('image').attr('height',height);
}
});
var position = $('svg').position();
$('.resize').css('top',position.top);
$('.resize').css('left',position.left);
css
.resize{
height: 120px;
width: 120px;
position:absolute;
z-index:0;
}
Upvotes: 4