Jquery Animate() 不工作

标签 jquery jquery-animate

本站“特色项目”部分有动画效果here .

我正在尝试为我的网站做这个,实际上我大约一个月前就这样做了。但现在令人惊讶的是,它根本不起作用,而且对于我来说,弄清楚问题可能是什么有点模棱两可。

我是否选择了错误的库,我的脚本是否有问题,或者是一个错误?

HTML。

      <a class="MainMiddleTwoEach MMTE1"  href="#" title="This is the title 1">
           <label class="MainMiddleTwoLabel1"></label>
           <span class="MainMiddleTwoLabel2"></span>    
      </a>

JS.

      $('.MainMiddleTwoEach').mouseenter(function (e) {
            pageId = $(this).attr('href');
            $(this).children('label').animate({ top: '150px' }, 300);
            $(this).children('label').animate({ top: '-100px' }, 300);
            $(this).children('span').animate({ top: '20px' }, 300);
            $(this).children('span').animate({ top: '230px' }, 300);
        }).mouseleave(function (e) {
            $(this).children('label').animate({ top: '130px' }, 300);
            $(this).children('label').animate({ top: '80px' }, 300);
            $(this).children('span').animate({ top: '-10px' }, 300);
            $(this).children('span').animate({ top: '55px' }, 300);
        });    

http://jsfiddle.net/K4Ak2/3

最佳答案

您需要将元素的位置设置为relativeabsolute才能使用toprightbottomleft 属性。

在这里查看我的编辑:http://jsfiddle.net/K4Ak2/4/

我在 CSS 中添加了一行

label, span { position: relative; }

它应该按预期工作。

关于Jquery Animate() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15429553/

相关文章:

jquery - 如何解决mouseover和mouseout的响应能力

javascript - 检测点击了哪个链接?始终返回未定义。怎么了?

php - 从所选变体向 WooCommerce 变量产品标题添加一些属性值

javascript - 根据选择的选项运行 JQuery 动画

javascript - jQuery .animate 函数在切换选项卡时行为不正常

javascript - 根据当前节分配索引#

php - Ajax + Json + PHP $_POST 不返回值

javascript - Trello-引用 client.js 文件并且无法在 Trello.authorize API 中调用类型为“Success”的函数

javascript - 创建扩展时出现 Qlik Sense 错误

javascript - 使一组图像移动穿过屏幕,然后当离开窗口时,它从另一侧出现