444 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
TahaH-Studio says
$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width() - 6;
        $(this).width(newImgWidth);
    });
});

Hey guys, I wrote the above code to resize any image on my website by 6px. Its working fine in ff, IE but not in Chrome or Safari (webkit). Any ideas why its not working?

Thanks

447 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels says

try this:

$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width();
        $(this).css('width', parseFloat(newImgWidth - 6) + 'px');
    });
});

good luck ;)

444 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
TahaH-Studio says
try this:
$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width();
        $(this).css('width', parseFloat(newImgWidth - 6) + 'px');
    });
});
good luck ;)

Still doesn’t work. My code works only when I add the width attribute to the element. Is there anyway (with jguery) to automatically add the width attribute to the element?

73 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+3 more
illusionem says

try using your img code in $(window).load(function(){ }); webkit browsers render css and js in parallel this should do it ;)

86 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $40,000+ on Envato Market
  • Located in Belgium
+4 more
BrentChesny says
try this:
$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width();
        $(this).css('width', parseFloat(newImgWidth - 6) + 'px');
    });
});
good luck ;)
Still doesn’t work. My code works only when I add the width attribute to the element. Is there anyway (with jguery) to automatically add the width attribute to the element?
$(document).ready(function(){
    $("img").each(function(){ 
        var newImgWidth = $(this).width();
        $(this).attr('width', parseFloat(newImgWidth - 6));
    });
});
444 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in United Kingdom
TahaH-Studio says
try using your img code in $(window).load(function(){ }); webkit browsers render css and js in parallel this should do it ;)

@abhin2cool, Thanks alot mate. That worked :D, you rock ;)

@BCProducties, I haven’t tried your suggestion but thanks for your reply. I really appreciate it :)

by
by
by
by
by
by