Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-05-21
3
Medium Priority
?
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Assisted Solution

by:Rainer Jeschor
Rainer Jeschor earned 750 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
The viewer will learn how to dynamically set the form action using jQuery.
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)

715 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