Jquery resize duplicating code ?
Hello.
I am having trouble trying to set a height with resize() because every time i resize the screen it adds another svg. I can see why its doing it. It is adding more because it is creating the svg inside the packagesvg() which is inside the $(window).resize(). but I can't find a way to fix it?
Thanks
This is the code:
The JS file:
- function packagesvg() {
var w = $('.pillar').outerWidth();
var h = $('.pillar').outerHeight();
var paper = Raphael("buyingSvg");
paper.setViewBox(0,0,w,h,true);
-
var svg = document.querySelector("svg");
-
$('#buyingSvg').css({'border':'2px solid red','width':w+'px','height':h+'px'});
$(svg).css({'border':'2px solid blue','width':w+'px','height':h+'px'});
-
- }
- $(document).ready(function (){
packagesvg();
$(window).resize(function() {
packagesvg();
});
- });
The HTML code
- <div class="pillar">
<div id="buyingSvg"></div>
</div>
The output is like this at first
- <div id="buyingSvg" style="border: 2px solid red; width: 190px; height: 538px;" >
<svg height="342" version="1.1" width="190" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative; top: -0.333008px; border: 2px solid blue; width: 190px; height: 538px;" viewBox="0 0 190 538" preserveAspectRatio="xMidYMid meet" >
</div>
But when i resize the page it keeps adding more..
- <div id="buyingSvg" style="border: 2px solid red; width: 190px; height: 538px;" >
<svg height="342" version="1.1" width="190" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative; top: -0.333008px; border: 2px solid blue; width: 190px; height: 538px;" viewBox="0 0 190 538" preserveAspectRatio="xMidYMid meet" >
-
<svg height="342" version="1.1" width="190" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative; top: -0.333008px; border: 2px solid blue; width: 190px; height: 538px;" viewBox="0 0 190 538" preserveAspectRatio="xMidYMid meet" >
-
<svg height="342" version="1.1" width="190" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative; top: -0.333008px; border: 2px solid blue; width: 190px; height: 538px;" viewBox="0 0 190 538" preserveAspectRatio="xMidYMid meet" >
-
<svg height="342" version="1.1" width="190" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative; top: -0.333008px; border: 2px solid blue; width: 190px; height: 538px;" viewBox="0 0 190 538" preserveAspectRatio="xMidYMid meet" >
-
<svg height="342" version="1.1" width="190" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden; position: relative; top: -0.333008px; border: 2px solid blue; width: 190px; height: 538px;" viewBox="0 0 190 538" preserveAspectRatio="xMidYMid meet" >
</div>
how can i fix this issue?
thanks
Ricky