查询 | Animate() 改变 DIV 位置的问题

标签 jquery css jquery-animate css-position

我正在使用 position:0px;position:-135px; 当有人将鼠标悬停在它上面时上下移动 div。我正在使用 jQuery 为 DIV 设置动画,以便它在 onmouseover 上向上移动并在 onmouseout 上向下移动。

下面是我试过的 jQuery 代码:

function show_slide_preview(id_to_preview){

    id_to_preview = "#" + id_to_preview;

    $(id_to_preview).animate({
        bottom: "0px",
    }, 1000 );
}

function show_slide_unpreview(id_to_preview){

    id_to_preview = "#" + id_to_preview;

    $(id_to_preview).animate({
        bottom: "-135px",
    }, 1000 );
}

下面是HTML示例代码:

<div class="slideshow_option_one_underlay" onmouseout="show_slide_unpreview('slide_1_button_preview');" onmouseover="show_slide_preview('slide_1_button_preview');" onclick="change_slide('slide_1');" id="slide_1_button">

        <img src="images/about_us_slider.png">

        <div class="slideshow_option_one slideshow_options" onclick="change_slide('slide_1')" id="slide_1_button_preview">
            <h3>About Us</h3>
            <p>Find out about our origins and what we can offer your business.</p>
            <a href="javascript:{}">Click Here To Read More</a>
        </div></div>

问题

这确实有效,但是我得到了一个滑稽的结果,因为它们不断地上下弹跳而且不停下来!!下面是它的 GIF 动图。

如何解决这个烦人但有趣的错误?

最佳答案

您要确保在元素上调用“.stop()”以停止当前动画,这将防止动画过度排队。

function show_slide_preview(id_to_preview){

id_to_preview = "#" + id_to_preview;

$(id_to_preview).stop().animate({
    bottom: "0px",
}, 1000 );}

function show_slide_unpreview(id_to_preview){
id_to_preview = "#" + id_to_preview;

$(id_to_preview).stop().animate({
    bottom: "-135px",
}, 1000 );}

关于查询 | Animate() 改变 DIV 位置的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32319645/

相关文章:

javascript - 成功后使用 dropzone 更新 Angular js 上的选项卡

javascript - 传递节时触发函数 - jquery

jquery - 使用 JQuery 设置 div 的高度属性会产生不一致的行为

css - HTML 标题中的彩色字符

jquery - IE7 和 jquery 动画 : using jquery 1. 3.2、coda-slider 2.0 和 jquery.easing 1.3 的奇怪问题

jquery - 使用 jQuery 在 Firefox 和 Internet Explorer 中呈现模糊的文本

javascript - 从工具提示中获取属性

javascript - IE6 : width or height set to 0px does not work when content inside

javascript - 如何将两个 jquery 对象一起制作动画

javascript - jQuery:如何检查选定的下拉项是否已在文本框列表中?