javascript - How to develop an edit option on hover of a div - Stack Overflow

I'm trying to use the hover option to display an small edit imagebutton in the top right hand cor

I'm trying to use the hover option to display an small edit image/button in the top right hand corner of a div. I have a dynamically created table of x by y number of cells. What I would like to do is have a tiny edit button in the top right hand corner that allows me to click on that button and bring up a popup window.

Something similar to the following:

where the user is presented with options over the div on hover. Would this need to be done in javascript or css? I am using javascript to create the table as follows:

    var col = document.getElementById("NoColumns").value;
    var row = document.getElementById("NoRows").value;
    if (col > 0 || row > 0) {
        $("#tblDash").show();
        $("#NumberOfColumns").val(col);
        $("#NumberOfRows").val(row);

        for (var x = 1; x <= row; x++)
        {
            tr = document.createElement('tr');
            document.getElementById('table').appendChild(tr);

            for (var i = 1; i <= col; i++) {
                var td = document.createElement('td');
                td.className = "drop";
                td.id = x + ', ' + i;
                td.setAttribute('onclick', 'clicked(this);')
                td.appendChild(document.createTextNode(i));
                tr.appendChild(td);
            }
        }

I'm trying to use the hover option to display an small edit image/button in the top right hand corner of a div. I have a dynamically created table of x by y number of cells. What I would like to do is have a tiny edit button in the top right hand corner that allows me to click on that button and bring up a popup window.

Something similar to the following:

where the user is presented with options over the div on hover. Would this need to be done in javascript or css? I am using javascript to create the table as follows:

    var col = document.getElementById("NoColumns").value;
    var row = document.getElementById("NoRows").value;
    if (col > 0 || row > 0) {
        $("#tblDash").show();
        $("#NumberOfColumns").val(col);
        $("#NumberOfRows").val(row);

        for (var x = 1; x <= row; x++)
        {
            tr = document.createElement('tr');
            document.getElementById('table').appendChild(tr);

            for (var i = 1; i <= col; i++) {
                var td = document.createElement('td');
                td.className = "drop";
                td.id = x + ', ' + i;
                td.setAttribute('onclick', 'clicked(this);')
                td.appendChild(document.createTextNode(i));
                tr.appendChild(td);
            }
        }
Share Improve this question asked Feb 1, 2019 at 7:43 user1397978user1397978 2651 gold badge8 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Display the button when you hover on the container, else keep it hidden via CSS?

.container {
  height: 200px;
  width: 200px;
  background-color: yellowgreen;
  position: relative;
}

.container:hover > .btn {
  display: block;
}

.btn {
  display: none;
  position: absolute;
  top: 5px;
  right: 5px;
}
<div class="container">
  <button class="btn">Edit</btn>
</div>

It will be done with CSS. add "button" class to these three buttons and use the css below.

.button {
    display: none;
}

div:hover + .button, .button:hover {
    display: inline-block;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745048070a4608216.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信