Passing variable between functions
Hi Guys,
I'm trying to scale some images that are imported into the page. I'm setting up a dummy test image to get the orig. width, but the width is coming up undefined. Strange since I'm reading in src for the image.
I tried setting up a closure function & even using window.variable, but nothing works.
Can someone please help me with this code.
- function scaImage() {
- $(function() {
- var oiwd;
- $('div[class^="searcher_stack-its_img"] img').each(function() {
- var testi = new Image();
- testi.src = $(this).attr("src");
- $(testi).css({'visibility': 'hidden'});
- $(testi).appendTo('body');
- var isco = $(this).data("simgsc");
- console.log('Orig Scale: ' + isco);
- console.log('Image: ' + testi.src);
- $(testi).on("load", function() {
- oiwd = testi.width;
- window.searcheriowd = oiwd;
- console.log('Orig Wd: ' + oiwd); // undefined
- });
- testi.remove();
- oiwd = window.searcheriowd;
- console.log('Orig Wd: ' + oiwd);
- if (oiwd != 0 && testi.src != '') {
- console.log('Src Check: ' + testi.src);
- console.log('Scale Factor: ' + isco);
- var scwd = Math.round(parseInt(oiwd) * parseInt(isco) / 100);
- console.log('Scaled Wd: ' + scwd);
- $(this).css({'width': scwd + 'px'});
- }
- });
- });
- }
Thanks, Bill