I'm looking for a way to trigger for a different function on each individual image. I'm using the Galleria Jquery plugin and have it set up on my site. The problem is i want to display a div with information depending on which image is loaded. I can't figure out how to capture which image is displayed and how to create a condition based on it.
A:
I'm not very familiar with that plug-in, but if your images are being pulled from a database, you could associate either a set range of data (like categories) or specific data per each item (like, say, a caption) with each of the images, so when they're pulled over, you can have jQuery extrapolate that data into your plug-in.
dclowd9901
2010-03-12 18:32:32
A:
There's an "onImage" callback, and it's passed the image element being displayed. If you give each image an "id" value, or if you just look at the "src" attribute, then you can know what information to display.
Pointy
2010-03-12 18:39:39
I'd tried reading the source attribute and even the $galleria.current which holds the url of the image being displayed with no luck. There's something about my code that can't access the corrent value at the right time.
Landitus
2010-03-14 16:53:57
A:
UPDATED
DEMO: http://jsbin.com/egavo/6
without hacking the original Galleria plugin, just adding this into your code!
CSS PART:
/* HOVER CSS EFFECT */
.imageteaser {
margin: 0;
overflow: hidden;
float: left;
position: relative;
}
.imageteaser:hover {
cursor: pointer;
}
.imageteaser .more {
position: absolute;
right: 20px;
bottom: 20px;
font-size: 1.2em;
color: #fff;
background: #000;
padding: 5px 10px;
filter:alpha(opacity=65);
opacity:.65;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=65)"; /*--IE 8 Transparency--*/
}
.imageteaser .desc { display: none; }
.imageteaser:hover .more { visibility: hidden;}
.imageteaser:hover .desc{
display: block;
font-size: 1.2em;
background: #111;
filter:alpha(opacity=75);
opacity:.75;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)"; /*--IE 8 Transparency--*/
color: #fff;
position: absolute;
bottom: 11px;
left: 0;
padding: 10px 5px;
margin: 0;
width: 702px;
border-top: 1px solid #999;
text-align:left
}
.imageteaser:hover .desc strong {
display: block;
margin-bottom: 5px;
font-size:1.5em;
float:right;
margin-right:20px
}
JQUERY ( Latest Version ) PART:
$(".gallery_demo_unstyled img").click( function() {
var src = $(this).attr('src');
$('.imageteaser').remove();
$('.galleria_wrapper').before('<div class="imageteaser">'+
'<img src="'+src+'" alt="" />'+
'<span class="more">> read more</span>' +
'<span class="desc">'+
'<strong>click</strong>'+
$(this).attr('title') +
'</span></div>');
$('.galleria_wrapper').attr('style','display:none');
}).filter(':first').click();
$(".imageteaser .desc strong").live( 'click' , function() {
alert('run function!');
});
This Do exactly what you want! ;-)
let me know!
aSeptik
2010-03-12 22:18:47
Thanks a lot for the code, AND the demo! That's a plus!! I just figure out that I need to know which code to run under each image, which is similar to what @Pointy is trying to achieve. I think this is as close as it gets, though. Thanks again!
Landitus
2010-03-14 16:52:26
sorry, but have you seen the alert('run function!'); just replace it with your function! ;-)
aSeptik
2010-03-19 10:34:01