dpzff20644 2012-08-18 15:06
浏览 38

一旦图像加载,PHP foreach就会回显

I currently have some php code which gets the thumbnail of random Wordpress posts but the problem is when I run it none of the images show until every image has been downloaded. I was wondering if there is a way to echo the image then go to the next one. Thanks.

 <?php
                    $args = array( 'numberposts' => 25, 'orderby' => 'rand' );
                    $rand_posts = get_posts( $args );
                    foreach( $rand_posts as $post ) : ?>
                    <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?>
                    <li id="photo-<?php the_ID(); ?>" class="visible scroll-content-item ui-widget-header"><a href="<?php the_permalink(); ?>"><img width="80" height="80" src="<?php echo $url; ?>" class="attachment-small-grid wp-post-image" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" /></a> </li>
                    <?php endforeach; ?>
  • 写回答

1条回答 默认 最新

  • duanke1286 2012-08-18 15:09
    关注

    PHP cannot tell you when an image has downloaded, as it is a server side language. You have to use javascript to write code based on browser based events, like images loading.

    www.farinspace.com/jquery-image-preload-plugin/

    That jQuery plugin will let you execute functions based on each image loading, and then on all images loading... I might start there.

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)