我想知道是否有人可以帮助我。
使用下面的脚本,我正在用fancyBox创建一个图像gllery。
<!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/> ← 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;">
<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'));
?>
<img src="cross.png" class="removeImage" alt="Remove this image" align="top"/>
<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>
通过本网站的一些建议,我为每个图像添加了一个“十字”图标,最终将用于删除图像。
我真的很喜欢jQuery和样式表等,但我希望能够做的是将十字架放在实际图像的左上角而不是,因为它现在显示在顶部的div。我在这里列出了相关页面的链接 here
我很欣赏那些经验丰富的devleoper,这可能非常简单,但正如我所说,我上周才真正开始使用jQuery和CSS文件。
我只是想知道是否有人可以就如何解决这个问题提供一些指导。
非常感谢和问候
答案 0 :(得分:1)
您必须重新格式化HTML输出并添加额外的样式才能执行此操作。
因此,对于for
循环中的每个图像,请使用以下代码:
<div style="display: inline-block; position: relative;">
<a class="fancybox" rel="allimages" title="<?php echo $name; ?>" href="<?php echo $source; ?>">
<img src="<?php echo $thumbnail; ?>" alt="<?php echo $description; ?>">
</a>
<a href="#delete" style="position: absolute; left: 0; top: 0;">
<img src="cross.png" class="removeImage" alt="Remove this image" align="top">
</a>
</div>
否则,您可以通过应用CSS类来实现:
.myimage {
display: inline-block;
position: relative;
}
.cross {
position: absolute;
left: 0;
top: 0;
}
将这些类添加到HTML标记中:
<div class="myimage">
<a class="fancybox" rel="allimages" title="<?php echo $name; ?>" href="<?php echo $source; ?>">
<img src="<?php echo $thumbnail; ?>" alt="<?php echo $description; ?>">
</a>
<a href="#delete" class="cross">
<img src="cross.png" class="removeImage" alt="Remove this image" align="top">
</a>
</div>
答案 1 :(得分:1)
使用jQuery和CSS尝试这个,非常简洁和简单:
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
#del_icon {
position:absolute;
top:0;
left:0;
width:15px;
height:15px;
background:url('http://www.mapmyfinds.co.uk/development/cross.png');
background-repeat : no-repeat;
display:block;
z-index:2;
cursor:pointer;
display:none;
}
.image {
float:left;
position:relative;
}
.image a {
float:left;
display:inline;
position:relative;
z-index:1;
}
</style>
<script>
$(document).ready(function(){
$(".image").hover(function(){
$(this).find("#del_icon").show();
},
function()
{
$(this).find("#del_icon").hide();
});
});
</script>
</head>
<body>
<div class="image">
<a href="del.php?id=1" id="del_icon"><span></span></a>
<a href="http://www.mapmyfinds.co.uk/development/UploadedFiles/IRHM73/1/A-deer-in-Knole-Park-Seve-005.jpg"><img src="http://www.mapmyfinds.co.uk/development/UploadedFiles/IRHM73/1/A-deer-in-Knole-Park-Seve-005.jpg" alt="" width="150"/></a>
</div>
<div class="image">
<a href="del.php?id=2" id="del_icon"><span></span></a>
<a href="http://www.mapmyfinds.co.uk/development/UploadedFiles/IRHM73/1/Thumbnails/_47061196_greatbritainjpg.jpg"><img src="http://www.mapmyfinds.co.uk/development/UploadedFiles/IRHM73/1/Thumbnails/_47061196_greatbritainjpg.jpg" alt="" width="150"/></a>
</div>
<div class="image">
<a href="del.php?id=3" id="del_icon"><span></span></a>
<a href="http://www.mapmyfinds.co.uk/development/UploadedFiles/IRHM73/1/Thumbnails/Test_Pic_2.jpg"><img src="http://www.mapmyfinds.co.uk/development/UploadedFiles/IRHM73/1/Thumbnails/Test_Pic_2.jpg" alt="" width="150"/></a>
</div>
</body>
</html>