Solved

Magnify image when mouse click, or mouse over

Posted on 2014-03-26
2
482 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 26

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

774 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