how to show delete button in top right corner of Image?

后端 未结 7 1595
予麋鹿
予麋鹿 2021-01-31 17:53

i would like to show delete button at top right corner to image? how could i achieve this?

my html is like this :-

main image :



        
相关标签:
7条回答
  • 2021-01-31 18:08

    You should write a plugin for this

    (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);
    
    0 讨论(0)
  • 2021-01-31 18:09

    Usual approach with position: relative and position: absolute.

    HTML:

    <div class="img-wrap">
        <span class="close">&times;</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;
        ...
    }
    

    Extended demo (+ JS interaction) http://jsfiddle.net/yHNEv/

    0 讨论(0)
  • 2021-01-31 18:09

    I have coded one up for you http://jsfiddle.net/PPN7Q/

    You need to wrap the image in a DIV

    <div class="thumbnail">
    <img src="http://96pix.com/images/renee-v.jpg" />
     <a href="">Delete</a>
    </div>
    

    and apply the following CSS rules

    .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;
    }
    
    0 讨论(0)
  • 2021-01-31 18:16

    Try something like

    <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>
    

    Demo: Fiddle

    0 讨论(0)
  • 2021-01-31 18:24

    In my opinion you can just set style="position:absolute;top:0px;right:0px;" for RemoveButton.ico and style="position:relative;" for div with img

    0 讨论(0)
  • 2021-01-31 18:30
    <div style=" float: right;margin-left: 289px;position: absolute;">*</div>
    <img src="score.png" width="300" height="300" />
    

    Please try this. It might help.

    0 讨论(0)
提交回复
热议问题