@Lori
Our bad ... we posted so many things here that made this post
difficult to follow up.
I understand that you are not trying to get something FROM an alt
attribute, however, in order to put INTO the alt attribute of the
popped up image, you first need to get that content from somewhere
else ... in this case, the alt in the thumbnail.
The "beforeShow" option goes inside the fancybox script like
<script type="text/javascript">
$(document).ready(function() {
$(".fancybox").fancybox({
beforeShow: function(){
var fancyAlt = $(this.element).data("alt");
$(".fancybox-inner").find("img").attr("alt",fancyAlt);
}
}); // close fancybox
}); // close ready
</script>
you placed it after closing fancybox .... it was a simple syntax error
try copy and past from above
(and everybody please refrain from commenting until Lori solves here
issue, thanks)
On May 24, 9:31 am, "Lori K. Brown" <
lori...@brownphotos.com> wrote:
> Ok, I had to re-read the thread 3x to find that -- I thought I'd read
> everything. ???
>
> When I use that code, fancybox breaks, and I get the javascript error:
>
> Timestamp: 5/24/2012 12:29:28 PM
> Error: function statement requires a name
> Source File:
http://localhost/smcd/emb/mscat/
> Line: 43, Column: 23
> Source Code:
> beforeShow: function(){
>
> I'm sorry, I just don't understand what I'm doing wrong.
>
> I've implemented it in the head of my document like this:
>
> <script type="text/javascript"> $(document).ready(function()
> { $(".fancybox").fancybox(); beforeShow: function(){ var
> fancyAlt = $(this.element).find('img').attr('alt');
> $(".fancybox-inner").find("img").attr("alt",fancyAlt);
>
> } });</script>
>
> I'm sure I'm missing something basic, but I' just don't understand.
> ???
>
> Lori
>
> On Thu, May 24, 2012 at 12:22 PM, Francisco de Azevedo <
>
>
>
>
>
>
>
>
frandeazev...@gmail.com> wrote:
> > *@Lori:*
> > The code shared by JFK in option 1 will do exactly that:
> > *1. *Store each of your images' alt values before the slideshow loads;
> > *2. *Add each of the original images' alt values and assign it to the new
> > version of the image shown in the slideshow.
> > As long as your original images have an alt value specified, the alt value
> > will migrate to the slideshow as well.
> > Cheers!
>
> > Marventus
>
> > On Thu, May 24, 2012 at 1:14 PM, Lori Brown <
lorik...@gmail.com> wrote:
>
> >> This is nice, JFK, but I'm not trying to get something FROM an alt
> >> attribute, I want to get text put INTO the alt attribute of the popped up
> >> image.
>
> >> Here is my page:
> >>
http://www.star.nesdis.noaa.gov/smcd/emb/mscat/index.php
>
> >> And here is the relevant snip of code (line 89 of source):
>
> >> <a class="fancybox" title="NOAA/NESDIS/STAR MSU/AMSU-A/SSU global atmospheric temperature trends" href="images/MSU_AMSU_SSU_global_trend.gif"><img src="images/MSU_AMSU_SSU_global_trend_sm.gif"
> >> style="float: right; margin: 0px 0px 12px 12px" alt="NOAA/NESDIS/STAR MSU/AMSU-A/SSU global atmospheric temperature trends" title="NOAA/NESDIS/STAR MSU/AMSU-A/SSU global atmospheric temperature trends"></a>
>
> >> I want the text that is the alt text of the image (or if I have to put
> >> the alt on the link I will, doesn't matter) to be rendered into the alt
> >> attribute of the image that pops up. And I don't understand how to make
> >> that happen. ????
>
> >> Any suggestions?
>
> >> I see this suggestion above:
>
> >> $(".fancybox").fancybox({
> >> afterLoad: function( links, index ){
> >> var self = $(links[index]);
> >> var alt = self.attr('alt');
> >> $('
> >> **fancybox-image').attr('alt',**alt);
> >> }
> >> });
>
> >> but I don't understand which parts of this suggestion are real code and
> >> which parts are dummy labels.
>
> >> On Thursday, May 24, 2012 3:47:42 AM UTC-4, JFK wrote:
>
> >>> you can also check this
> >>>
http://groups.google.com/**group/fancybox/browse_thread/**
> >>> thread/7f2777fca8335aa4/<
http://groups.google.com/group/fancybox/browse_thread/thread/7f2777fc...>
> >>> and
> >>>
http://groups.google.com/**group/fancybox/browse_thread/**
> >>> thread/3da14d88af2393cc/<
http://groups.google.com/group/fancybox/browse_thread/thread/3da14d88...>
>
> >>> although they were written for v1.3.x, still gives you an idea how
> >>> title and alt attributes work with fancybox
>
> >>> On May 24, 12:31 am, Jime Ximbalo <
ximb...@gmail.com> wrote:
> >>> > Ah... interesting.
> >>> > Did not know that.
>
> >>> > Will check those ref-articles.
> >>> > Thanks
>
> >>> > Ximbalo
>
> >>> > On Thu, May 24, 2012 at 12:02 AM, JFK <
jfk.d...@gmail.com> wrote:
> >>> > > @Francisco:
> >>> > > I am not fancybox developer so I am not able to answer whether or
> >>> not
> >>> > > this feature will be implemented in future releases.
>
> >>> > > @Ximbalo:
> >>> > > If you set a title in the <a> tag (wrapping a thumbnail (<img> tag)
> >>> > > with alt attribute), the title attribute will show up on mouse hover
> >>> > > (tooltip) as well as the caption for fancybox. In other words, the
> >>> alt
> >>> > > from the thumbnail will only show up on mouse hover (tooltip) IF
> >>> there
> >>> > > is not title attribute AND in IE only.
>
> >>> > > If you want a different tooltip than the fancybox title, then check
> >>> > >
http://stackoverflow.com/a/**8425900/1055987or<
http://stackoverflow.com/a/8425900/1055987or>
> >>> > >
http://stackoverflow.com/a/**10609780/1055987<
http://stackoverflow.com/a/10609780/1055987>
> >>> > > >
http://www.dennisjackson.com/**HTML5/work.php<
http://www.dennisjackson.com/HTML5/work.php> <--
> >>> > > > > var fancyAlt = $(this.element).find('img').**attr('alt');
> >>> > > > > $(".fancybox-inner").find("**img").attr("alt",fancyAlt);
> >>> > > > > }
>
> >>> > > > > });
>
> >>> > > > > 2) passing the alt via "data-" attribute (requires HTML5
> >>> DOCTYPE) ...
> >>> > > > > useful when there is not thumbnail
> >>> > > > > html
> >>> > > > > <a class="fancybox" href="image02.jpg" data-alt="alt for image
> >>> > > > > 02">open image 02</a>
> >>> > > > > script
> >>> > > > > $(".fancybox").fancybox({
> >>> > > > > beforeShow: function(){
> >>> > > > > var fancyAlt = $(this.element).data("alt");
> >>> > > > > $(".fancybox-inner").find("**img").attr("alt",fancyAlt);
> >>> > > > > }
>
> >>> > > > > });
>
> >>> > > > > 3) hardcoding the alt attribute ... if preferred
> >>> > > > > html
> >>> > > > > <a class="fancybox" href="image03.jpg" >open image 03</a>
> >>> > > > > script
> >>> > > > > $(".fancybox").fancybox({
> >>> > > > > beforeShow: function(){
> >>> > > > > var fancyAlt = "alt for image 02";
> >>> > > > > $(".fancybox-inner").find("**img").attr("alt",fancyAlt);
> >>> > > > > }
>
> >>> > > > > });
>
> >>> > > > > My preferred would be the number 1 or 2 depending on whether
> >>> your are
> >>> > > > > using thumbnails or not.
>
> >>> > > > > So this is the answer for the original post: how to set the alt
> >>> > > > > attribute in the image inside fancybox?
> >>> > > > > Other questions should be treated in different posts
>
> >>> > > > > On May 23, 4:20 pm, Ximbalo <
ximb...@gmail.com> wrote:
>
> >>> > > > > > I believe that the following should achieve the desired
> >>> result.
>
> >>> > > > > > afterLoad : function()
> >>> > > > > > {
> >>> > > > > > var i = this.index;
> >>> > > > > > var aThumbs = $(".fancybox");
> >>> > > > > > var iLink = aThumbs.eq(i);
> >>> > > > > > var iThumb =
> >>> iLink.children(':first-child')**;
> >>> > > > > > var iAlt = iThumb.attr("alt");
> >>> > > > > > $(".fancybox-image").attr("**alt",
> >>> iAlt );
> >>> > > > > > }
>
> >>> > > > > > However... oddly enough... as I check the value of each "var"
> >>> > > above...
> >>> > > > > > they are correct!
> >>> > > > > > But the final line, to add the Thumbnail alt tag to the
> >>> currently
> >>> > > open
> >>> > > > > > image... has no effect.
> >>> > > > > > Not sure why... but if anybody can
>
> ...
>
> read more »