简体   繁体   English

php ajax自动刷新平滑

[英]php ajax auto refresh smoothing

The code is working fine, but since the function refreshes every 2 seconds, the image blinks abruptly and goes off. 代码工作正常,但是由于该功能每2秒钟刷新一次,因此图像会突然闪烁并熄灭。 How can I make it look smooth or not make it blink? 如何使它看起来光滑或不眨眼?

echo '<script>
window.setInterval(function() {
    yopahshareloader("'.$id.'"," '.$postype.'");
}, 2000);
</script>';

//the code calling the ajax function.
echo "<img onclick='respond(";
echo '"yo","' . $id . '"' . ',"' . $postype . '"';
echo " )' src='images/icons/yo.png' style='margin-bottom:5px;'/>";

Your code looks a little unclear, so I'll assume the image blinks because it's changing? 您的代码看起来有点不清楚,所以我认为图像会因为变化而闪烁?

Firstly google & searching stackoverflow will usually help you get your answer but here's what you're looking for. 首先,谷歌和搜索stackoverflow通常可以帮助您得到答案,但这就是您想要的。

You want load the image then display it, so what you can do is load it into javascript, bind an event for when it loads, and then do your magic :P 您想要加载图像然后显示它,所以您可以做的是将其加载到javascript中,在加载时绑定一个事件,然后执行魔术:P

//create image object
var image = new Image();

//add image path
image.src = "";

//bind load event
image.onload = function(){
    //now load next image
    // The image has loaded
}

So now you've stopped the blinking, you could look into using jQuery to allow for a fadeIn and fadeOut effect. 因此,现在您已停止闪烁,可以考虑使用jQuery来实现fadeIn和fadeOut效果。

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

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