简体   繁体   English

Javascript&CSS:“悬停”按钮在悬停时不会显示

[英]Javascript & CSS: Remove button won't show when hovered

Below is my code snippet. 以下是我的代码段。 I want the remove button to show when a thumbnail image is hovered. 我希望将鼠标悬停在缩略图上时显示删除按钮。 I press F12 to inspect element of the code, it showed that it was appended in the image but when a thumbnail image is hovered no remove button showed up. 我按F12键检查代码元素,它表明它已附加在图像中,但是当悬停缩略图时,没有显示删除按钮。 Can someone help me fix the issue? 有人可以帮我解决问题吗? Thank you in advance. 先感谢您。 Cheers! 干杯!

personDom.onclick = (function(person, that) {
return function(e) { 
    var retVal = c.faces.onclick(person);
    var input = inputBox[0].id;
    var divId;
    var requiredImgList = document.getElementById("imageReqDivList");
    var optionalImgList = document.getElementById("imageOpDivList");
    var fyiImgList = document.getElementById("imageFYIDivList");
    var arrayList;
    var unique = true;
    if(input == "required") {
        divId = "requiredImage";
        arrayList = requiredImgList.value.split(", ");
        for (var i = 0; i < arrayList.length; i++) {
            if(arrayList[i].startsWith(person.email)) {
                unique = false;
                alert("This person has already been added");
            }
        }
        if(unique) {
            requiredImgList.value = requiredImgList.value + person.email + ", ";
        }
     document.getElementById('required').value = "";
    } 
     else if(input == "optional") {   
         divId = "optionalImage";
         arrayList = optionalImgList.value.split(", ");
         for (var i = 0; i < arrayList.length; i++) {
             if(arrayList[i].startsWith(person.email)) {
                 unique = false;
                 alert("This person has already been added");
             }
         }
         if(unique) {
             optionalImgList.value = optionalImgList.value + person.email + ", ";
         }   
         document.getElementById('optional').value = "";
     }
     else if(input == "fyi") {   
         divId = "fyiImage";
         arrayList = fyiImgList.value.split(", ");
         for (var i = 0; i < arrayList.length; i++) {
             if(arrayList[i].startsWith(person.email)) {
                 unique = false;
                 alert("This person has already been added");
             }
         }
         if(unique) {
            fyiImgList.value = fyiImgList.value + person.email + ", ";
         }
         document.getElementById('fyi').value = "";
    }
    if(unique) {
       get_data(person.email, person.uid, divId);
    }

    //If the click handler returns a value, then put it in the input
    if ( typeof retVal == "string" ) {
       h.setValue(inputBox, retVal);
       this.hideResults();
       inputBox[0].focus();

    }
}.bind(that);
})(result, this);

Javascript Java脚本

function get_data(email, userId, divId) {
createImage("https://www.apparels.com/image/"+ useId +"?s=60", email, useId, divId);
}

function createImage(src, alt, title, divId) {
     var img = document.createElement("img");
     img.style.zIndex = -1;
     var imgDelIcon = document.createElement("a");
     imgDelIcon.style.zIndex = 1;
     img.src = src;
     if (alt != null) img.alt = alt;
     if (title != null) img.title = title;
     imgDelIcon.href = "#";
     imgDelIcon.className = "delete";
     img.setAttribute("class", "img-circle");
     document.getElementById(divId).appendChild(img); 
     document.getElementById(divId).parentNode.appendChild(imgDelIcon);
}

HTML HTML

    <div class="form-group">
    <label class="control-label col-md-3" for="event">Required:</label>
    <div class="col-md-7">
        <input type="event" class="typeahead form-control" id="required" placeholder="Enter required attendees">
        <div id="container">
            <div id="requiredImage" alt="Faces"></div>
        </div>
        <textarea id="imageReqDivList" hidden="true" readonly="true"></textarea>
    </div> 
</div>

    <div class="form-group">
        <label class="control-label col-md-3" for="event">Optional:</label>
        <div class="col-md-7">
            <input type="event" class="typeahead form-control" id="optional" placeholder="Enter optional attendees">
            <div id="optionalImage" alt="Faces"></div>
            <textarea id="imageOpDivList" hidden="true" readonly="true"></textarea>
        </div> 
    </div>

    <div class="form-group">
        <label class="control-label col-md-3" for="event">FYI:</label>
        <div class="col-md-7">
            <input type="event" class="typeahead form-control" id="fyi" placeholder="Enter to be informed attendees">
            <div id="fyiImage" alt="Faces"></div>
            <textarea id="imageFYIDivList" hidden="true" readonly="true"></textarea>
        </div> 
    </div>

CSS CSS

    Remove.css:
#container { 
    overflow:auto; 
}
.image { 
    width:60px;
    height:60px;
    float:left;
    position:relative; 
}
a.delete { 
    display:none;
    position:absolute;
    top:0;
    right:-3;
    width:20px;
    height:20px;
    background-size: auto 30px;
    border-radius: 50px;
    text-indent:-999px;
}
a.delete:hover { 
    border: 1px solid blue;
}
.image:hover 
a.delete { 
    display:block; 
}


Demo.css:
body {
    font-family: sans-serif;
    text-align: center;
    background-color: #fafafa;
}
header h1 {
    font-size: 5em;
    color: #6c7d95;
    font-weight: bold;
    text-shadow: 1px 1px white, -1px -1px black;
    /* text-shadow: #fff 1px 1px 0; */ 
    margin: 30px 0;
}
.typeahead {
    width: 490px;
    padding: 5px;
    border: 1px solid #888888;
    /* -moz-box-shadow: 0px 0px 2px 0px #e4e4e4; */
    -moz-box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.75);
}

Can you reproduce your issue in this link 您能否在此链接中重现您的问题

https://plnkr.co/edit/yUa9OlT7QAgcioeqscdN https://plnkr.co/edit/yUa9OlT7QAgcioeqscdN

function get_data(email, userId, divId) {
 createImage("https://www.apparels.com/image/"+ useId +"?s=60", email, useId, divId);
}

Sorry guys my bad. 抱歉,我不好。 I modified my javascript and remove.css to show remove button when hovered. 我修改了我的javascript和remove.css以便在悬停时显示“删除”按钮。

In Remove.css, I eliminate position: absolute in a.delete. 在Remove.css中,我消除了a.delete中的position:absolute。

#container { 
    overflow:auto; 
}
.image { 
    width:60px;
    height:60px;
    float:left;
    position:relative; 
}
a.delete { 
    display:none;
    top:0;
    right:-3;
    width:20px;
    height:20px;
    background-size: auto 30px;
    border-radius: 50px;
    text-indent:-999px;
}
a.delete:hover { 
    border: 1px solid blue;
}
.image:hover 
a.delete { 
    display:block; 
}

Javascript Java脚本

function createImage(src, alt, title, divId) {
        var img = document.createElement("div");
        img.style.backgroundImage = "url("+ src +")";
        if (alt != null) img.alt = alt;
        if (title != null) img.title = title;
        img.setAttribute("class", "img-circle");

        var imgDelIcon = document.createElement("button");
        imgDelIcon.style.zIndex = 1;
        imgDelIcon.type = "button";
        imgDelIcon.className = "remove";

        document.getElementById(divId).appendChild(img);
        img.appendChild(imgDelIcon);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击时javascript切换不起作用,但将鼠标悬停在按钮上时css起作用 - javascript toggle not working whenclicked but css works when a button is hovered over 单击按钮时,音频控件不会显示JavaScript - Audio controls won't show when button is clicked JavaScript 按钮在CSS或Javascript中从普通按钮上悬停并按下了ianage? - Button hovered and pressed ianages from normal button in CSS or Javascript? (HTML + JavaScript + BootStrap) 带有删除按钮的表格不会显示 - (HTML + JavaScript + BootStrap) Table With Delete Button Won't Show up 在单击按钮之前,Javascript幻灯片演示不会显示第一个数组 - Javascript Slideshow Won't Show First Array Until the Button is Clicked javascript查询选择器在单击按钮时不会切换CSS设置 - javascript query selector won't toggle css setting on button click 下拉菜单中的“ Twitter关注”按钮将不显示用户名 - Twitter Follow button won’t show username when in dropdown 从高图悬停时如何去除外部阴影JAVASCRIPT - How to remove outer shadow when hovered from highcharts JAVASCRIPT CSS / JavaScript - 在元素悬停时添加:焦点状态 - CSS/JavaScript - Adding the :focus state when an element is hovered 悬停的项目在展开时不会显示隐藏的元素 - Hovered item doesn't show hidden elements when it expands
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM