Solved

Magnify image when mouse click, or mouse over

Posted on 2014-03-26
2
483 Views
Last Modified: 2014-03-28
Wanted to that all the images in my website with name beginning by Cnt .... (Like CntImage1, CntImage2, ....), could increase the size automatically when click them.
0
Comment
Question by:rflorencio
2 Comments
 
LVL 8

Accepted Solution

by:
soupBoy earned 300 total points
ID: 39956783
Without a lot of information, here is a basic example I created: Using JQuery and CSS3 Scale to change image size

You could easily change the selector to work with image name instead of class by doing the following:
$('img[src*="/Cnt"]').on('click', function(){
//blah blah blah
});

Here is the code from my example:
HTML:
<ul>
    <li>
        <img src="http://www.byui.edu/images/agriculture-life-sciences/flower.jpg" class="magnify" /> 
    </li>
    
    <li>
        <img src="http://www.byui.edu/images/agriculture-life-sciences/flower.jpg" class="magnify" /> 
    </li>
    
    <li>
        <img src="http://www.byui.edu/images/agriculture-life-sciences/flower.jpg" class="magnify" /> 
    </li>
    
    <li>
        <img src="http://www.byui.edu/images/agriculture-life-sciences/flower.jpg" class="magnify" /> 
    </li>
</ul>

Open in new window

CSS:
ul{
    list-style-type: none;
}
img{
    width: 150px;
}
.clicked{
    transform:scale(1.5, 1.5);
    -webkit-transform:scale(1.5, 1.5);
}

Open in new window

Javascript (JQuery):
$('.magnify').on('click', function(){
   $(this).toggleClass('clicked');
    $('.magnify').not($(this)).each(function(i,v){
       $(v).removeClass('clicked'); 
    });
});

Open in new window


Let me know if this doesn't work for you!

- Chris
0
 
LVL 27

Assisted Solution

by:skullnobrains
skullnobrains earned 200 total points
ID: 39961006
or simply ?

$('img[src*="/Cnt"]').on('click', function(){
  $(this).css('transform','scale(1.5, 1.5)');
});

or without relying on css3

$('img[src*="/Cnt"]').on('click', function(){
  $(this).width($(this).width()*1.5);
  $(this).height($(this).height()*1.5);
});
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

820 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