繁体   English   中英

为什么我的jQuery动画效果不起作用?

[英]Why won't my jQuery animate effect work?

这是html,全部在头:

    <script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.js"></script>

第二个是我的js文档! js文档如下所示:

$(document).ready(function() {

    $("li").fadeTo(0, 0.6),

    $("li").mouseenter(function() {
        $(this).fadeTo(100, 1),
        $(this).animate({top: "-=20px"},"fast")
    });
    $("li").mouseleave(function() {
        $(this).fadeTo(100, 0.6),
        $(this).animate({top: "=20px"},"fast")
    });


});

不透明度有效,但动画无效,这是怎么回事?

如果要对top CSS进行动画处理,则<li>元素的位置值必须为fixedrelativeabsolute 没有它,动画仍将完成,但是您不会在浏览器中看到任何视觉效果。

 $(document).ready(function() { $("li").fadeTo(0, 0.6), $("li").mouseenter(function() { $(this).fadeTo(100, 1), $(this).animate({top: "-=20px"},"fast") }); $("li").mouseleave(function() { $(this).fadeTo(100, 0.6), $(this).animate({top: "=20px"},"fast") }); }); 
 li { position:absolute; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> 

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM