悬停按钮时移动移动 div

2022-01-22 00:00:00 hover jquery javascript html mousehover

表格单元格中的(链接)按钮修复(但单击时链接不起作用.)

A (link) button fix in table cell (But link not working when clicked.)

悬停按钮时如何移动另一个移动"div?

How to move another 'Moving' div, when hovering the button?

代码:

HTML

<table cellpadding="0" cellspacing="0" border="0" width='650' height='320' style="border: 1px solid #000; position: absolute; top: 300px;">
    <tr>
        <th>
            <div class="Fly" style="position: absolute; left: 300px; top: -300px;">
                <div id="Superman"></div>
            </div>
            <div class="button" style="position: absolute; left: 80px; top: 60px;">
<a href="https://stackoverflow.com/questions/25909457/moving-div-moving-whole-page"></a>

            </div>
        </th>
    </tr>
</table>

CSS

#Superman {
    background: url(http://www.comixoasis.com/v/vspfiles/templates/runner/images/homepage/Superman.png) no-repeat;
    width:250px;
    height:300px;
    background-size: 90%;
    transition: 3s ease;
}
#Superman:hover {
    background: url(http://www.mc-villalobos.com/sources/superman.png) no-repeat;
    background-size: 100%;
    transform: translate(0, 350px);
    /*move-down*/
}
.button {
    background: url(http://iconbug.com/data/26/256/a2ccff2488d35d8ebc6189ea693cb4a0.png) no-repeat;
    width:300px;
    height:300px;
}
.button:hover {
    background: url(http://1.bp.blogspot.com/__JNFVYfijS4/SX9bD7dk07I/AAAAAAAAAXw/VJCkHGqZFx4/s400/Happy.png) no-repeat;
    width:300px;
    height:300px;
}

JS

    $(document).ready(function () {

    function moveDown() {
        $('.Fly').animate({
            'marginTop': "+=100px"
        }, 1000, moveUp)
    }

    function moveUp() {
        $('.Fly').animate({
            'marginTop': "-=100px"
        }, 1000, moveDown)
    }
    moveUp();
});

演示

推荐答案

你的 a 元素是空的:

<div class="button" style="position: absolute; left: 80px; top: 60px;">
  <a href="https://stackoverflow.com/questions/25909457/moving-div-moving-whole-page">
  </a>
</div>

div 移到其中,它应该可以工作:

Move the div inside it, and it should work:

<a href="https://stackoverflow.com/questions/25909457/moving-div-moving-whole-page">
  <div class="button" style="position: absolute; left: 80px; top: 60px;">
  </div>   
</a>

相关文章