简体   繁体   English

Javascript-从一项过渡到另一项,会短暂弹出

[英]Javascript - fading from one item to another pops up with both briefly

I have a testimonials area on my website that fades from one testimonial to another. 我的网站上有一个推荐区,从一个推荐区到另一个推荐区。 I'm having an issue where it will fade out too slowly before the next item fades in causing both to come up making a large div making it look ugly. 我遇到一个问题,即在下一个项目消失之前,它的消失速度会太慢,导致两者都出现一个较大的div,从而使其看起来很难看。

I want it to fade from one testimonial to another without jumping and flashing with both. 我希望它从一种推荐逐渐消失到另一种,而又不会两者同时闪烁。

You can see an example here: http://ledragonvert.com/index_test.php 您可以在此处查看示例: http : //ledragonvert.com/index_test.php

Here is my Javascript code: 这是我的Javascript代码:

function rotate_p() {
if (p_current == p_count) {
p_current = 1;
} else {
p_current++;
}
var $container = $('#container');
$container.find('p').fadeOut();
$container.find('p:nth-child(' + p_current + ')').fadeIn();
}

var p_count;
var p_current = 0;
var p_interval;
$(document).ready(function () {
rotate_p();
p_count = $('#container').find('p').length;
p_interval = setInterval(function () {rotate_p();}, 7000);
});

Thanks you very much for taking your time out to help me. 非常感谢您抽出宝贵的时间来帮助我。

the solution is CSS based. 该解决方案基于CSS。 since the position of the "p" element is static and you call both fadeOut and fadeIn, there is an overlap, as two p elements are inevitably shown together. 因为“ p”元素的位置是静态的,并且您同时调用了fadeOut和fadeIn,所以存在重叠,因为两个 p元素不可避免地一起显示。 To get them one on top of the other you need to use absolute positioning on the p element, like so: 为了使它们一个接一个,您需要在p元素上使用绝对定位,如下所示:

 #container {
 position:relative;
  }
 #container>p {
    position:absolute;
   //use any values you wish, to set the testimonial relative to #container:
   top:10px; 
   left:50px; 
   }

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

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