简体   繁体   English

使用.slideUp的功能不会设置动画

[英]function using .slideUp doesn't animate

ok first thing the function - 好的,第一件事是功能-

//function to change page   
function changePage(newPage) {
    $('.current').slideUp();
    $('.current').removeClass('current');
    $(newPage).addClass('current');
    $('h3.title').text('');
    $('.slider_container').empty();
    $(newPage).slideDown();
}

how its called 怎么称呼它

$('.specialistLink').on('click', function(event) {
    event.preventDefault();
    $('#footerLinks').removeClass('hide');
    $('header').css({'border-bottom': '10px solid #738c1f'});
    changePage("#page3");
    $('h3.title').text('dp-specialist').css({'color' : '#738c1f'}); 
    $('#page3 .left ul a:first').click();
    $('#footerLinks .left').css({'background-color':'#738c1f'});
    $('#footerLinks .right').css({'background-color':'#c8c0b5'});
});

Dom element for the above click event 上述click事件的Dom元素

<a href="#" class="specialistLink">
<div class="left">
  <h3>dp-specialist ></h3>
</div>
</a> 

dom element to show/animate (minus the content for space reasons) 显示/动画的dom元素(出于空间原因,请减少内容)

<section id="page3" class="hide">
</section>

Now the problem - I have 2 links like this that are identical (except #page to load, css values to change and the class that triggers the click), however this one never animates - it displays just fine (the content changes and #page3 shows) but the current #page does not slide up and the new one doesn't slide in except if #page3 is currently in view already in which case it does slide in. 现在的问题-我有两个相同的链接(除了要加载的#page,要更改的css值和触发点击的类),但是此链接从不动画-它显示得很好(内容更改和#page3显示),但当前的#page不会向上滑动,而新的#page不会滑动到其中,除非#page3当前已在视图中,在这种情况下它确实会滑入。

maybe using a callback function for the slideUp will fix your problem (not sure, though): 也许对slideUp使用回调函数可以解决您的问题(不过不确定):

function changePage(newPage) {
    $('.current').slideUp('slow',function() {
        $('.current').removeClass('current');
        $(newPage).addClass('current');
        $('h3.title').text('');
        $('.slider_container').empty();
        $(newPage).slideDown();
    });

}

This will execute all that stuff inside the second function once the slideUp animation is complete 一旦slideUp动画完成,这将在第二个函数中执行所有操作

See if adding the current class after the animation is done will help out. 看看动画完成后是否添加当前类会有所帮助。

//$(newPage).addClass('current');
$('h3.title').text('');
$('.slider_container').empty();
$(newPage).slideDown(400, function(){ $(this).addClass("current"); } );

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

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