简体   繁体   中英

JQuery - Image Fade w/ Php Variables

I have thumbnail images below a larger image. The thumbnails, when clicked, need to fade out the current large image, and fade in the thumbnail's large image. All the images and theumbnails are being pulled from the database.

Whats the best way to go about doing this?

$(document).ready(function(){
    $('.thumbnail').live('click', function(){
        var self = this;
        $('#hero img').fadeOut(function(){
            $('#hero img').attr('src', self.src.replace('50x50', '572x362')).fadeIn();
        });
   });
});

the client side, using jQuery, would look something like:

$('.thumbnail').live('click', function(ev){
   ev.preventDefault();
   var self = this;
   $('.largeImage').fadeOut(function(){
      $('.largeImage').attr('src', self.src.replace(/_sm/, '_lg')).fadeIn();
   });
});

Your PHP then just generates the markup with <img class="thumbnail" src="some_img_sm.jpg"> and some div <img class="largeImage">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM