Solved

Magnify image when mouse click, or mouse over

Posted on 2014-03-26
2
479 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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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