【问题标题】:Add png Icon To HTML将 png 图标添加到 HTML
【发布时间】:2012-04-28 13:01:40
【问题描述】:

我想知道是否有人可以帮助我。

首先道歉,因为对于某些人来说这可能是一个非常基本的问题,但我是新手,所以请多多包涵。

我正在使用下面的脚本在 fancyBox 中创建一个图片库。

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


  <script type="text/javascript">  

            $('.fancybox').fancybox({
                openEffect  :   'elastic',
                closeEffect :   'elastic',

                padding :   20,
                fitToView   :   true,

                prevEffect :    'none',
                nextEffect :    'none',

                closeBtn  : false,
                arrows : false,

                helpers : {
                    title : {
                        type : 'inside'
                    },
                    buttons : {}
                },

                afterLoad : function() {
                    this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : '');
                }
            });


</script> 
  <style type="text/css">
<!--
.style1 {
    font-size: 14px;
    margin-top: 5px;
    margin-right: 110px;
}
-->
  </style>  
</head>
<body style="font-family: Calibri; color:  #505050; margin-left: 240px; float:left;"/>
<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" style="margin-left: -120px; margin-right: 50px; border-left: 100; caption-side: left;"> 

    <p>
      <?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" title="<?php echo $name; ?>" href="<?php echo $source; ?>"><img src="<?php echo $thumbnail; ?>"alt="<?php echo $description; ?>" /></a>
      <?php endfor; ?>  
    </p>
</form>  
</body>
</html> 

我现在想要添加允许用户删除图像的功能。

使用“famfamfam.com”中的“丝绸图标”,我找到了一个合适的图标,我想将其放置在每张图片的左上方,但我不确定如何将图标添加到我的页面。

我试图在网上找到一个教程来告诉我如何做到这一点,但到目前为止还没有成功。

我只是想知道是否有人可以提供一些指导我如何将其添加到我的页面。

非常感谢和问候

【问题讨论】:

    标签: jquery icons fancybox


    【解决方案1】:

    就在这一行之前:

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

    您可以添加如下内容:

    <img src="path/to/image.png" class="removeImage" alt="Remove this image" />
    

    然后用 jQuery 做这样的事情:

    $('.removeImage').click(function(){
        $(this).next('a.fancybox').remove();
    });
    

    我还会对文档进行许多其他更改。例如,最好删除所有内联样式,并将它们组合成一个外部样式表。您的 javascript 也是如此。此外:

    • 您尝试像这样自动关闭您的开始正文标签:&lt;body /&gt; — 我们不这样做。
    • 使用font-family 时,最好创建一个网络安全的字体列表。查看更多信息:http://cssfontstack.com/
    • 不推荐使用 HTML 中的 align 属性

    我对您的文档进行了一些更改,以便于使用。这是 HTML/PHP:

    <!doctype html>
    <!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
    <!--[if IE 7 ]>    <html class="ie7"> <![endif]-->
    <!--[if IE 8 ]>    <html class="ie8"> <![endif]-->
    <!--[if IE 9 ]>    <html class="ie9"> <![endif]-->
    <!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
    <head>  
    
    <title>Gallery</title>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
    
    <!-- styles -->
    <link rel="stylesheet" type="text/css" href="fancybox/source/helpers/jquery.fancybox-thumbs.css?v=1.0.2" />
    <link rel="stylesheet" type="text/css" href="fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.2" />
    <link rel="stylesheet" type="text/css" href="fancybox/source/jquery.fancybox.css?v=2.0.6" media="screen" />
    <link rel="stylesheet" type="text/css" href="screen.css" media="screen" />  
    </head>
    
    <body>
    <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">
    <p>
    <?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" title="<?php echo $name; ?>" href="<?php echo $source; ?>"><img src="<?php echo $thumbnail; ?>"alt="<?php echo $description; ?>" /></a>
      <?php endfor; ?>  
    </p>
    </form>
    
    <!-- scripts -->
    <script type="text/javascript" src="fancybox/lib/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="fancybox/source/jquery.fancybox.js?v=2.0.6"></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-thumbs.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="main.js"></script>
    </body>
    </html>
    

    ...这是你的样式表——screen.css:

    body {font-family: Calibri; color: #505050; margin-left: 240px; float:left;}
    .style1 {font-size: 14px; margin-top: 5px; margin-right: 110px;}
    #gallery {margin-left: -120px; margin-right: 50px; border-left: 100; caption-side: left;}
    

    最后是页面准备就绪后运行的脚本——main.js:

    $(function(){
        $('.removeImage').click(function(){
            $(this).next('a.fancybox').remove();
        });
    
    $('.fancybox').fancybox({
                openEffect  :   'elastic',
                closeEffect :   'elastic',
    
                padding :   20,
                fitToView   :   true,
    
                prevEffect :    'none',
                nextEffect :    'none',
    
                closeBtn  : false,
                arrows : false,
    
                helpers : {
                    title : {
                        type : 'inside'
                    },
                    buttons : {}
                },
    
                afterLoad : function() {
                    this.title = 'Image ' + (this.index + 1) + ' of ' + this.group.length + (this.title ? ' - ' + this.title : '');
                }
            });
    })
    

    【讨论】:

    • 您好,非常感谢您对图标的帮助和对样式表的指导。我会做出改变。亲切的问候
    • 我可能有点过于热心回答这个问题,但这一切都有帮助!
    • 嗨,别担心。这很棒,尤其是从初学者的角度来看。真诚的感谢和问候
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 2011-01-10
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 2019-06-24
    • 2022-11-10
    相关资源
    最近更新 更多