Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
生成随机图像到另一个div.PHP的高度_Php_Jquery_Image_Height - Fatal编程技术网

生成随机图像到另一个div.PHP的高度

生成随机图像到另一个div.PHP的高度,php,jquery,image,height,Php,Jquery,Image,Height,这段代码目前从MyImages目录中随机选取6幅图像,并将它们放在侧边栏中显示。问题是,我不希望侧边栏只显示6幅图像,我希望侧边栏生成的图像与我的主要内容div的高度相匹配。 for($i = 0 ; $i < $imagesCount ; $i++) { $randomIndex = array_rand($images); $file_title = $randomImage = $images[$randomIndex]; unset($images[$randomIndex]

这段代码目前从MyImages目录中随机选取6幅图像,并将它们放在侧边栏中显示。问题是,我不希望侧边栏只显示6幅图像,我希望侧边栏生成的图像与我的主要内容div的高度相匹配。
for($i = 0 ; $i < $imagesCount ; $i++) {

$randomIndex = array_rand($images); 

$file_title = $randomImage = $images[$randomIndex];
unset($images[$randomIndex]);
?>
<a href="<?php echo $randomImage ?>"><img src="<?php echo $randomImage ?>"
     width="100%" height="150%"; alt="" /> <br /><br /></a>

<?php
}
?>
($i=0;$i<$ImageScont;$i++)的
{
$randomIndex=数组随机($images);
$file_title=$randomImage=$images[$randomIndex];
未设置($images[$randomIndex]);
?>
现在我的想法是使用jquery查找div的高度并生成图像,直到使用类似以下伪代码的值达到该高度:
for($i=0;$i<$(“#内容”).height();$i++{
随机图像在这里;
}


这里的问题(除了我将JQuery和PHP混合在一起这一事实之外,我稍后会解决这个问题)是.height()将返回一个以像素为单位的值,从而随机生成800-1200个随机图像。是否有人对如何解决此问题有任何想法?这是一个指向该页面的链接,以便您可以在出现任何混淆时了解我的意思。

确实有很多方法可以解决此问题,但是

使用php像这样创建dom元素,并将它们作为变量传递给jQuery:

<?php

$images = howeverYourGettingYourSixImages();

for($i=0; $i<count($images); $i++){
    $image_array[]='<img  class="images" src="'.$images[$i].'"/>';
}

echo('<script type="text/javascript">var images='.json_encode($image_array).'</script>');
?>

jQuery应该做一件事:获取高度。听起来它已经在这样做了。php应该做一件事:根据高度返回图像。php接受高度,然后计算要返回多少图像。是的,但我不想要800个随机图像,这是最后一个代码段要做的。不知何故,我需要找到一种方法来避免这种情况o添加每个随机生成的图像的高度,并生成更多图像,直到主div的高度小于添加图像的高度。如果这有意义。如果希望使用php动态获取图像:将php放入外部脚本中,并通过AJAX返回图像数组,而不是像exa中那样重复结果例如。让我知道你是否正在尝试这样做,我可以举一个例子。感谢你的快速回复,以及我如何处理这一问题的实际细节。echo对我处理静态6个图像很好。真正的问题只是能够确定何时停止生成图像。如果你检查该链接,你会看到有时E6图像对于页面内容来说太多了(已经设置为)。我需要一些时间才能将您的代码应用到我的页面中,但我会让您知道它是否有效!我肯定是JQuery新手,更喜欢呆在PHP领域。
<div id="content"></div>
<script type="text/javascript">

    var container = jQuery('#content');
    var container_height = container.height();
    var image_height = container_height / images.length;
    jQuery.each(images,function(k,v){
       container.append(v);
    });
    jQuery(".images").height(image_height);;

</script>
<style type="text/css">
    #content{
            height: 600px;
    }
    .images{
            float:left;
            clear:both;
    }
</style>