【问题标题】:My animations arent working as expected我的动画没有按预期工作
【发布时间】:2015-03-31 13:26:20
【问题描述】:

我尝试在 5 秒后淡入视频,然后在按下按钮后淡出视频,然后将页面滚动到下一部分。

在下一部分,它应该为一些 div 设置动画,然后....按下按钮进入下一部分,淡出为之前动画的 div 设置动画,然后进入下一部分。

第三个滚动按钮根本不起作用。

只有最后 2 个滚动按钮有效....我不明白为什么只有最后 2 个,而不是前 3 周。

注意:我还想取消页面上的滚动条,并通过滚动按钮导航页面。这是给我带来麻烦的代码:

<script>


$(document).ready(function(){

//Kill Page Scrollbar    
$('html, body').css({
    'overflow': 'hidden',
    'height': '100%'
});


//animate the registration video fading in
$('#Video').fadeTo(3000, 1); 
//Make scrollbutton clickable
$('.ScrollButton_White1').click(function(){
//Fade Video out
     $('#Video').fadeTo(3000, 0), (function(){
//define the variable "diamonds"
    var diamonds = $('#PresenterContainer').children()
//animate the scrolling of the page down to the anchor point//                                     
$('html, body').animate({
  scrollTop: $("#PresenterContainer_AnchorPoint").offset().top
    }, 5000,
                            function() {
         diamonds.show();

                          });
     });
});

<!--scroll button 2-->               
$('.ScrollButton_Gold1').click(function(){

         diamonds.hide();   

$('html, body').animate({
            scrollTop: $("#YouAskedForIt_AnchorPoint").offset().top
                    }, 5000
 );
});


<!--scroll button 3-->
$('.ScrollButton_White3').click(function(){

        $('html, body').animate({
            scrollTop: $("#ReturnChampion_AnchorPoint").offset().top
                    }, 5000
);                                                                  
});

<!--scroll button 4-->
$('.ScrollButton_Gold1').click(function(){

        $('html, body').animate({
            scrollTop: $("#YouAskedForIt_AnchorPoint").offset().top
                    }, 5000);                  


                 });

<!--scroll button 5-->
$('.ScrollButton_Gold2').click(function(){

        $('html, body').animate({
            scrollTop: $("#WhatYouWillLearn_AnchorPoint").offset().top
                    }, 5000);                  


                 });

<!--animate presenter diamond buttons-->
<!--$(window).scroll(function(event) {


            <!--$('#Diamond_DarrenHardy').addClass('animate_rf');
            <!--$('#Diamond_RobertKiyosaki').addClass('animate_rf');-->



    <!--});

<!--end jquery script-->    
});
 </script>

【问题讨论】:

  • 您似乎正在即时创建一些东西,请尝试使用现场活动。
  • -2- 和 -4- 都使用相同的选择器 .ScrollButton_Gold1diamonds 对 -1- 是本地的,但 -2- 尝试使用它。您应该在控制台中看到错误。在编写/检查代码时要更加小心。

标签: javascript jquery html css jquery-animate


【解决方案1】:

您的代码中似乎有错字

$('#Video').fadeTo(3000, 0), (function() {
        //define the variable "diamonds"
        var diamonds = $('#PresenterContainer').children()
        //animate the scrolling of the page down to the anchor point//
        $('html, body').animate({
                scrollTop: $("#PresenterContainer_AnchorPoint").offset().top
            }, 5000,
            function() {
                diamonds.show();

            });
    });

$('#Video').fadeTo(3000, 0), (function() {如果你想使用fadeTo的回调功能,应该是

$('#Video').fadeTo(3000, 0, function() {
        //define the variable "diamonds"
        var diamonds = $('#PresenterContainer').children()
        //animate the scrolling of the page down to the anchor point//
        $('html, body').animate({
                scrollTop: $("#PresenterContainer_AnchorPoint").offset().top
            }, 5000,
            function() {
                diamonds.show();

            });
    });

【讨论】:

  • 我的代码仍然没有按照我想要的方式运行,即使进行了编辑。现在它会在页面加载后立即为滚动设置动画......不是在寻找那个
  • 我更新的代码应该已经进入点击处理程序。您能否将您的代码放入 JSFiddle 中
  • 你没有添加你的 html 并且你已经替换了我示例中错误的代码部分
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-02
  • 2018-11-07
  • 2014-06-28
  • 2015-11-17
  • 2010-10-30
  • 1970-01-01
相关资源
最近更新 更多