【问题标题】:limit jquery random image with MVC使用 MVC 限制 jquery 随机图像
【发布时间】:2012-10-28 05:39:57
【问题描述】:

我在这里遇到了一点麻烦,我有一些脚本来自这个链接jQuery, random div order,我用这个脚本来调用我的 MySQL 查询。

我的问题是,例如我有 8 条记录,但我已经限制只显示 4 条记录,我希望所有记录都可以显示,即使我已经限制显示它。怎么样?

这里是我的模型

public function get_ads_query(){
    $row = $this->db->get('advertise');

    return $row;

}

这是我的代码

<div id="advertentie" class="advcontainer">
    <?php 
        $row = $this->M_front->get_ads_query();
        $row = $row->result();
        foreach($row as $ads):
    ?>
    <div class="adblock"><img src="<?php echo base_url(); ?>images/advertise/<?php echo $ads->Picture; ?>" /></div>
    <?php endforeach;?>
</div>

这里是 jquery

var $container = $(".advcontainer");

setInterval(function(){
    $container.html(shuffle($container.children().get()));
}, 1500);
$(".advcontainer div").each(function(){
    var color = $(this).attr("class");
    $(this).css({backgroundColor: color});
});
function shuffle(o){
    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
    return o;
};

谢谢

【问题讨论】:

    标签: javascript jquery random


    【解决方案1】:

    我找到了答案,最终耐心地使用谷歌的力量,然后找到了这个链接show and hide several random divs using jquery。再次非常感谢stackoverflow

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多