gpt4 book ai didi

Jquery fadeIn 导致滚动顶部,我该如何解决?

转载 作者:行者123 更新时间:2023-12-01 00:01:31 24 4
gpt4 key购买 nike

我对 jQuery fadeIn(或 fadeOut)方法有疑问。我建立了一个文章旋转器,一切正常但是当页面滚动到底部并且文章旋转时出现问题,fadeIn(或fadeOut)方法导致滚动到文章位置。我认为这些方法改变了body的css top属性,但我不知道如何避免这种情况!有什么想法吗???

这里是代码

    function rotate(direction)
{
if($('articles > article:visible:first') == 'undefined')
$currentArticle = $('articles > article:first');
else
$currentArticle = $('articles > article:visible:first');

if($currentArticle.attr('id') == $('articles > article:last').attr('id'))
$next = $('articles > article:first');
else
$next = $currentArticle.next();

if($currentArticle.attr('id') == $('articles > article:first').attr('id'))
$prev = $('articles > article:last');
else
$prev = $currentArticle.prev();

if($do_animation)
{
$currentArticle.fadeOut(1000,function(){
switch(direction)
{
case 1:
$next.fadeIn(1000);
break;
case -1:
$prev.fadeIn(1000);
break;
}
if($('.rotate_show'))
$('.rotate_show').removeClass('rotate_show');
$('article_number > btn[id|="'+$next.attr('id')+'"]').addClass('rotate_show');
});
}
else
return false;
}

好的,这里是网站 http://kario91.altervista.org/ultimate文本来自 joomla 这是完整的网站!变量工作正常,没有问题..尝试缩小浏览器窗口并滚动底部

最佳答案

我想说这个问题是由于当您的文章完全淡出时,就在调用回调之前,页面的高度降低了(因为文章被隐藏),因此,浏览器向上滚动,直到页面底部(没有文章)位于浏览器窗口的底部。尝试在 fadeOut 完成后删除回调,您可能会注意到浏览器如何对齐底部。

我认为你可以通过在淡出之前给文章容器一个高度来解决这个问题,当淡出完成时,在淡入开始后立即删除这个高度......或者类似的东西。

希望这会有所帮助!

关于Jquery fadeIn 导致滚动顶部,我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4916992/

24 4 0
文章推荐: Jquery 表单验证自定义错误放置在
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com