Solved

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

Posted on 2013-05-21
3
285 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

937 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

7 Experts available now in Live!

Get 1:1 Help Now