Solved

jQuery:    imageresize()  { if ((contentwidth) < 700px ){ ...do something  } else {  ....do nothing

Posted on 2013-05-21
3
280 Views
Last Modified: 2013-05-26
Hi Experts

I'm trying to get a bunch of images in a <div> to resize when the screen width is less than  700px --I got it to work with one image, which you can see online: www.amazinggirl.com.au.
Now I'm trying to get all images to resize within a <div id="fluid-content">... I thought I might achieve this with   imageSRCArray = imageSRC.split('_');  wih two versions of all the images: "BlaBla_big.png"  and  "BlaBla_small.png"  trying to split the imageSRCArray[2]   but it's not working...

 $(document).ready(function() {  
 function imageresize() {  
            var contentwidth = $('#content').width();  
              if ((contentwidth) < '700'){  
                $('.fluidimage').attr(function(){
                imageSRC = $(this).find('img').attr('src');
                imageSRCArray = imageSRC.split('_');
                $(this).find('img').attr('src', 'img/big_' + imageSRCArray[2]);
            } else {function() {
                $(this).find('img').attr('src', 'img/small_' + imageSRCArray[2]);
             }  
            }  
  
 imageresize();//Triggers when document first loads      
  
 $(window).bind("resize", function(){//Adjusts image when browser resized  
   imageresize();  
   });
  });

Open in new window


Here's the HTML:
<div id="content">  
 <img class="fluidimage" src="img/big_logo.png"/> 
  
  <div style="width: 100%; margin: 10% 0 10% 1.5%">
      <img src="img/big_toolBox.png" alt="Click & Choose" style="float: left; margin-top: 5%"/>
      <img src="img/big_girl.png" alt="Click & Choose" style="float: right;"/> 
  </div>
</div>

Open in new window


Here's the CSS:
#container{  width :100%;height:100%;  }
.fluidimage {  width: 100%;  }

Open in new window


Here's the images folder:
img folder
0
Comment
Question by:georgehowell
  • 2
3 Comments
 
LVL 44

Assisted Solution

by:Rainer Jeschor
Rainer Jeschor earned 250 total points
ID: 39183894
Hi,
sorry have just limited time, but you should move your function OUTSIDE of the document.ready handler and just call it from there.
So structure would be:
function ImageResize ...
document.ready (
call imageresize
bind window event
)
HTH
Rainer
0
 

Accepted Solution

by:
georgehowell earned 0 total points
ID: 39183939
I FOUND IT!

$(document).ready(function() {  
 
 function imageresize() {  
  var contentwidth = $('#content').width();

  $('img').each(function( index ) {
        //document.write($(this).attr('src'));
        var imageSRCArray = $(this).attr('src').split('_');
        if ((contentwidth) < '700'){
              $(this).attr('src',imageSRCArray[0] + '_small.png');
        } else {  
              $(this).attr('src',imageSRCArray[0] + '_big.png');  
        }
  });
 }  

 imageresize();//Triggers when document first loads      
 
 $(window).bind("resize", function(){//Adjusts image when browser resized  
   imageresize();  
  });  
 });


thanks for your comment Rainer, but I got to talk to another friend and he suggested this and it works
0
 

Author Closing Comment

by:georgehowell
ID: 39197414
original code had syntax errors - solution came through another source
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now