Html 在每个页面上重新加载新的背景图像

Html 在每个页面上重新加载新的背景图像,html,css,wordpress,background,Html,Css,Wordpress,Background,如何在网站上刷新的每个页面上显示新的背景图像(如果有帮助,请使用Wordpress)?我还想考虑不同的屏幕分辨率,并对此进行适当处理。任何帮助都将不胜感激。JavaScript可能是您最好的选择。您可以使用GD库实时生成它来检测屏幕分辨率,您可以使用客户端JavaScript screen.height screen.width 要显示不同的图像,您可能需要使用脚本生成一个随机数,并显示与其关联的图像。。。? 您可以将“当前”图像存储在会话中,并在每次生成新的随机数时检查它是否不会显示最后一个

如何在网站上刷新的每个页面上显示新的背景图像(如果有帮助,请使用Wordpress)?我还想考虑不同的屏幕分辨率,并对此进行适当处理。任何帮助都将不胜感激。

JavaScript可能是您最好的选择。

您可以使用GD库实时生成它来检测屏幕分辨率,您可以使用客户端JavaScript

screen.height
screen.width
要显示不同的图像,您可能需要使用脚本生成一个随机数,并显示与其关联的图像。。。? 您可以将“当前”图像存储在会话中,并在每次生成新的随机数时检查它是否不会显示最后一个……

您在wordpress codex中看到过吗


它解释了如何旋转标题图像。适应您的需要应该不会太难。

只要有自己的脚本,每次访问时都会随机返回图片即可。我在下面的URL中用C写了一张图片,每次都返回不同的图片。


这就是我使用Wordpress随机旋转网站标题图像的方法

代码是别人写的,我不记得是谁写的。将下面的php代码放入名为rotate.php的文件中,然后将rotate.php放入要旋转的图像目录(即“headerimages”),rotate.php将从中绘制。在头部图像使用的任何DIV中,从CSS样式表调用rotate.php

我不明白你能处理不同的屏幕分辨率是什么意思。最终用户屏幕分辨率

<?php


/*

    Call this way: <img src="http://example.com/rotate.php">


    Set $folder to the full path to the location of your images.
    For example: $folder = '/user/me/example.com/images/';
    If the rotate.php file will be in the same folder as your
    images then you should leave it set to $folder = '.';

*/


    $folder = '.';


    $extList = array();
    $extList['gif'] = 'image/gif';
    $extList['jpg'] = 'image/jpeg';
    $extList['jpeg'] = 'image/jpeg';
    $extList['png'] = 'image/png';


$img = null;

if (substr($folder,-1) != '/') {
    $folder = $folder.'/';
}

if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
        isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
        file_exists( $folder.$imageInfo['basename'] )
    ) {
        $img = $folder.$imageInfo['basename'];
    }
} else {
    $fileList = array();
    $handle = opendir($folder);
    while ( false !== ( $file = readdir($handle) ) ) {
        $file_info = pathinfo($file);
        if (
            isset( $extList[ strtolower( $file_info['extension'] ) ] )
        ) {
            $fileList[] = $file;
        }
    }
    closedir($handle);

    if (count($fileList) > 0) {
        $imageNumber = time() % count($fileList);
        $img = $folder.$fileList[$imageNumber];
    }
}

if ($img!=null) {
    $imageInfo = pathinfo($img);
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    header ($contentType);
    readfile($img);
} else {
    if ( function_exists('imagecreate') ) {
        header ("Content-type: image/png");
        $im = @imagecreate (100, 100)
            or die ("Cannot initialize new GD image stream");
        $background_color = imagecolorallocate ($im, 255, 255, 255);
        $text_color = imagecolorallocate ($im, 0,0,0);
        imagestring ($im, 2, 5, 5,  "IMAGE ERROR", $text_color);
        imagepng ($im);
        imagedestroy($im);
    }
}

?>


有无数种方法可以做到这一点。你有什么特别的方法吗?一种在服务器上负载最小并且在所有浏览器中都能工作的方法。你说的不同屏幕资源是什么意思?最终用户屏幕分辨率?在这种情况下,它们如何/为什么重要?请看下面我的答案。OP寻求一般帮助,使用JavaScript是一个很好的解决方案。如果OP搜索“背景图像javascript”,他们会找到实际的代码。