我想在右上角显示删除按钮以显示图像? 我怎么能实现这个目标?
我的HTML是这样的: -
主要形象:
<img id="' + id + '" src="../Images/DefaultPhotoMale.png" class="' + item + '" width="40" height="40" alt="image" title="' + projectTitle + '" style="cursor:pointer" />
x按钮图像显示在上方图像的右上方
'<img id="' + item.Soid + '" src="../Images/RemoveButton.ico" style="display:none" title="Remove Specialization" />
请不要设置背景图片,我需要点击该删除按钮的事件 像这样的东西:
答案 0 :(得分:40)
使用position: relative
和position: absolute
的常用方法。
HTML:
<div class="img-wrap">
<span class="close">×</span>
<img src="http://lorempixel.com/100/80">
</div>
CSS:
.img-wrap {
position: relative;
...
}
.img-wrap .close {
position: absolute;
top: 2px;
right: 2px;
z-index: 100;
...
}
扩展演示(+ JS互动)http://jsfiddle.net/yHNEv/
答案 1 :(得分:1)
尝试类似
的内容<div style="position: relative">
<img src="http://www.google.co.in/images/srpr/logo4w.png" />
<img src="http://wecision.com/enterprise/images/icons/closeIcon.png" style="position: absolute; top: 4px; right: 5px"/>
</div>
演示:Fiddle
答案 2 :(得分:1)
我为你编了一个http://jsfiddle.net/PPN7Q/
您需要将图像包装在DIV中
<div class="thumbnail">
<img src="http://96pix.com/images/renee-v.jpg" />
<a href="">Delete</a>
</div>
并应用以下CSS规则
.thumbnail {
width:50px;
height:50px;
position:relative;
}
.thumbnail img {
max-width:100%;
max-height:100%;
}
.thumbnail a {
display:block;
width:10px;
height:10px;
position:absolute;
top:3px;
right:3px;
background:#c00;
overflow:hidden;
text-indent:-9999px;
}
答案 3 :(得分:0)
在我看来,您只需为style="position:absolute;top:0px;right:0px;"
设置RemoveButton.ico
,为style="position:relative;"
div
设置img
答案 4 :(得分:0)
<div style=" float: right;margin-left: 289px;position: absolute;">*</div>
<img src="score.png" width="300" height="300" />
请试试这个。这可能有所帮助。
答案 5 :(得分:0)
你可以试试这个:
<div style="position:relative; width:'mainimagewidth'">
main image<img src="" />
<span style="position:absolute; top:0; right:0;">ximage<img src="" /></span>
</div>
答案 6 :(得分:0)
你应该为这个
写一个插件(function ($, window, document, undefined) {
'use strict';
var defaults = {};
var Delete = function (element) {
// You can access all lightgallery variables and functions like this.
this.core = $(element).data('lightGallery');
this.$el = $(element);
this.core.s = $.extend({}, defaults, this.core.s)
this.init();
return this;
}
Delete.prototype.init = function () {
var deleteIcon = '<span id="lg-clear" class="lg-icon deletePicture"><span class="glyphicon glyphicon-trash"></span></span>';
this.core.$outer.find('.lg-toolbar').append(deleteIcon);
this.delete();
};
Delete.prototype.delete = function () {
var that = this;
var image_id = '';
this.core.$outer.find('.deletePicture').on('click', function () {
// get vars from data-* attribute
image_id = that.core.$items.eq(that.core.index).data('id');
table_name = that.core.$items.eq(that.core.index).data('table-name');
/**
* Remove Touchpoint Retailer Image
*/
var formData = new FormData();
formData.append('image_id', image_id);
$.ajax(......).success(function()
{
var thumbcount = that.core.$outer.find('.lg-thumb-item').length;
if(thumbcount >= 1) {
// remove slides
}
else {
that.core.destroy();
}
});
});
}
/**
* Destroy function must be defined.
* lightgallery will automatically call your module destroy function
* before destroying the gallery
*/
Delete.prototype.destroy = function () {
}
// Attach your module with lightgallery
$.fn.lightGallery.modules.delete = Delete;
})(jQuery, window, document);