首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >摆弄.animate()

摆弄.animate()
EN

Stack Overflow用户
提问于 2012-10-14 19:50:50
回答 1查看 125关注 0票数 0

我正在使用jQuery中的.animate函数,我对这个函数相当陌生,但是由于某些原因,我不能让它工作。不确定我可能会出错的地方。

首先,我在body标记中定义脚本...

代码语言:javascript
复制
<script>
$('.rgt_btn').click(function() {
  $('.ovlBox').animate({
    opacity: 0.0 // I hope this will work? I'm trying to fade this box out, and fade in another... Or something along lines of a carousel.
  }, {
    duration: 2000,
    specialEasing: {
      width: 'linear',
      height: 'easeOutBounce'
    },
    complete: function() {
      $(this).after('// I'm trying to display here another box, but not sure how I can achieve this? The entire <div> box code is quite long to paste here.');
    }
  });
});
</script>

就在它下面,我有我的盒子。

代码语言:javascript
复制
<div id="lmovlb" class="ovlBox"> <!-- Content, lots of it... -->
<div style="display: block;" class="lft_btn"></div>
<div style="display: block;" class="rgt_btn"></div>
</div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-14 20:06:08

这是一个演示的jsfiddle (请原谅糟糕的css)。请注意,正如我前面所说的,您应该将代码包装在一个函数中,并在页面加载时调用它。此外,如果可能,请使用外部js文件。

以下是如何实现这一点的示例:

代码语言:javascript
复制
var yourFunc = function() {
    $('.rgt_btn').click(function() {
        $('.ovlBox').animate({
            opacity: 0.0
        }, {
            duration: 2000,
            specialEasing: {
                width: 'linear',
                height: 'easeOutBounce'
            },
            complete: function() {
                alert("hello");
            }
        });
    });
}
$(document).ready(yourFunc);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12881935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档