最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unable To Show fancyBox Title - Stack Overflow

programmeradmin1浏览0评论

I wonder whether someone may be able to help please.

I'm a little new to this, so I'm sure to some this will be a basic question but please bear with me.

I'm using the script below to create a image gallery with fancyBox.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">  
<html xmlns="">  
<head>  
  <title>Gallery</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  <script type="text/javascript" src=".7.2/jquery.min.js"></script>   
  <script type="text/javascript" src="fancybox/jquery.fancybox-1.3.4.pack.js"></script> 
  <script type="text/javascript" src="fancybox/jquery.easing-1.4.pack.js"></script> 
  <script type="text/javascript" src="fancybox/jquery.easing-1.4.pack.js"></script>  
  <script type="text/javascript" src="fancybox/jquery.mousewheel-3.0.4.pack.js"></script>  
  <script type="text/javascript" src="fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.2"></script>  
  <script type="text/javascript" src="fancybox/source/helpers/jquery.fancybox-media.js?v=1.0.0"></script>  
  <script type="text/javascript" src="/fancybox/source/helpers/jquery.fancybox-thumbs.js?v=2.0.6"></script>  
  <link rel="stylesheet" href="fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.2" type="text/css" media="screen" />  
  <link rel="stylesheet" href="fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />  
  <link rel="stylesheet" href="fancybox/source/helpers/jquery.fancybox-thumbs.css?v=2.0.6" type="text/css" media="screen" />  

  <script type="text/javascript">  

$(document).ready(function() { 
    $("a.fancybox").fancybox({

        'centerOnScroll':'true',
        helpers : {
        title : {
            type : 'inside'
        }
    },


        'transitionIn':'elastic',
        'transitionOut':'elastic',
        'speedIn':600, 
        'speedOut': 200,
        'overlayShow':false
    });

});


</script>  

</head> 
<body style="font-family: Calibri; color:  #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: 100px; margin-right: 100px; margin-bottom: -10px; float: left; position: absolute;"> 
<div align="right" class="style1"> <a href = "javascript:document.gallery.submit()"/> Add Images <a/> &larr; View Uploaded Images </div> 
  <form id="gallery" name="gallery" class="page" action="index.php" method="post">   

                  <?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :  
                          $xmlFile = $descriptions->documentElement->childNodes->item($i);  
                          $name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');  
                          $description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');  
                          $source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));  
                          $thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail'));  
                  ?> 
        <a class="fancybox" rel="allimages" href="<?php echo $source; ?>"><img src="<?php echo $thumbnail; ?>" alt="<?php echo $name; ?>"/></a><?php endfor; ?> 
  </form>  
</body>  
</html> 

The problem I'm having is that I cannot create the title inside the image, or indeed anywhere else except on 'hover over' which seems to be the default setting. I've tried all manner of different ways to try and get this to work.

i.e.

$(document).ready(function() { 
    $("a.fancybox").fancybox({

        'centerOnScroll':'true',
        'titleShow':'true',
        'titlePosition':'inside',
        'transitionIn':'elastic',
        'transitionOut':'elastic',
        'speedIn':600, 
        'speedOut': 200,
        'overlayShow':false
    });

});

and

 $(document).ready(function() { 
        $("fancybox").fancybox({

            'centerOnScroll':'true',
            'titleShow':'true',
            'titlePosition':'inside',
            'transitionIn':'elastic',
            'transitionOut':'elastic',
            'speedIn':600, 
            'speedOut': 200,
            'overlayShow':false
        });

    });

I've tried adding and deleting ', deleting spaces, all without success. I just wondered whether someone could perhaps look at this and let me know where I'm going wrong.

Many thanks and regards

I wonder whether someone may be able to help please.

I'm a little new to this, so I'm sure to some this will be a basic question but please bear with me.

I'm using the script below to create a image gallery with fancyBox.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3/1999/xhtml">  
<head>  
  <title>Gallery</title>  
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  <script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.7.2/jquery.min.js"></script>   
  <script type="text/javascript" src="fancybox/jquery.fancybox-1.3.4.pack.js"></script> 
  <script type="text/javascript" src="fancybox/jquery.easing-1.4.pack.js"></script> 
  <script type="text/javascript" src="fancybox/jquery.easing-1.4.pack.js"></script>  
  <script type="text/javascript" src="fancybox/jquery.mousewheel-3.0.4.pack.js"></script>  
  <script type="text/javascript" src="fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.2"></script>  
  <script type="text/javascript" src="fancybox/source/helpers/jquery.fancybox-media.js?v=1.0.0"></script>  
  <script type="text/javascript" src="/fancybox/source/helpers/jquery.fancybox-thumbs.js?v=2.0.6"></script>  
  <link rel="stylesheet" href="fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.2" type="text/css" media="screen" />  
  <link rel="stylesheet" href="fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />  
  <link rel="stylesheet" href="fancybox/source/helpers/jquery.fancybox-thumbs.css?v=2.0.6" type="text/css" media="screen" />  

  <script type="text/javascript">  

$(document).ready(function() { 
    $("a.fancybox").fancybox({

        'centerOnScroll':'true',
        helpers : {
        title : {
            type : 'inside'
        }
    },


        'transitionIn':'elastic',
        'transitionOut':'elastic',
        'speedIn':600, 
        'speedOut': 200,
        'overlayShow':false
    });

});


</script>  

</head> 
<body style="font-family: Calibri; color:  #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: 100px; margin-right: 100px; margin-bottom: -10px; float: left; position: absolute;"> 
<div align="right" class="style1"> <a href = "javascript:document.gallery.submit()"/> Add Images <a/> &larr; View Uploaded Images </div> 
  <form id="gallery" name="gallery" class="page" action="index.php" method="post">   

                  <?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :  
                          $xmlFile = $descriptions->documentElement->childNodes->item($i);  
                          $name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');  
                          $description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');  
                          $source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));  
                          $thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail'));  
                  ?> 
        <a class="fancybox" rel="allimages" href="<?php echo $source; ?>"><img src="<?php echo $thumbnail; ?>" alt="<?php echo $name; ?>"/></a><?php endfor; ?> 
  </form>  
</body>  
</html> 

The problem I'm having is that I cannot create the title inside the image, or indeed anywhere else except on 'hover over' which seems to be the default setting. I've tried all manner of different ways to try and get this to work.

i.e.

$(document).ready(function() { 
    $("a.fancybox").fancybox({

        'centerOnScroll':'true',
        'titleShow':'true',
        'titlePosition':'inside',
        'transitionIn':'elastic',
        'transitionOut':'elastic',
        'speedIn':600, 
        'speedOut': 200,
        'overlayShow':false
    });

});

and

 $(document).ready(function() { 
        $("fancybox").fancybox({

            'centerOnScroll':'true',
            'titleShow':'true',
            'titlePosition':'inside',
            'transitionIn':'elastic',
            'transitionOut':'elastic',
            'speedIn':600, 
            'speedOut': 200,
            'overlayShow':false
        });

    });

I've tried adding and deleting ', deleting spaces, all without success. I just wondered whether someone could perhaps look at this and let me know where I'm going wrong.

Many thanks and regards

Share Improve this question edited Apr 26, 2012 at 17:19 John Conde 220k99 gold badges463 silver badges502 bronze badges asked Apr 26, 2012 at 17:18 IRHMIRHM 1,32611 gold badges78 silver badges131 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

In this line:

<a class="fancybox" rel="allimages" href="<?php echo $source; ?>"><img src="<?php echo $thumbnail; ?>" alt="<?php echo $name; ?>"/></a><?php endfor; ?> 

Try setting the title attribute inside the a, not the alt tag inside the img. So it bees:

<a class="fancybox" rel="allimages" title="<?php echo $name; ?>" href="<?php echo $source; ?>"><img src="<?php echo $thumbnail; ?>" /></a><?php endfor; ?> 

In case adding a title element to your anchor tag does not work you can force the title in your fancybox settings

$(document).ready(function() { 
  $("fancybox").fancybox({
    'title'          : 'yourtitle'
    'centerOnScroll' : 'true',
    'titleShow'      : 'true',
    'titlePosition'  : 'inside',
    'transitionIn'   : 'elastic',
    'transitionOut'  : 'elastic',
    'speedIn'        : 600, 
    'speedOut'       : 200,
    'overlayShow'    : false
  });
});
发布评论

评论列表(0)

  1. 暂无评论