将图像动态加载到Vegas全屏幕背景图像插件中

时间:2012-11-28 17:49:22

标签: jquery image wordpress background

我正在尝试动态加载图片:::在WordPress :::

中包含以下代码

这就是我计划获取图像数据的原因:::

//For Demo I'm simulating some data
$url = 'http://localhost/lolo-wp/wp-content/uploads/2012/10/image_02.jpg,http://localhost/mocha/wp-content/uploads/2012/11/image_02.jpg';


$urls = explode(',', $url);

    if( is_array($urls) ) {

      // $vega_bg ='';
      foreach( $urls as $url ) {
         $vega_bg[] = "{ src:'{$url}' }";
      }
    }

将我想发送给Vegas :::

的所有属性本地化
// Localization 
wp_localize_script( 'vegas_init', 'vegassettings', array(
  'delay' => 5000,
  'fade'  => 1000,
  'backgrounds' => $vega_bg
));

我的拉斯维加斯初始化:::

vega_delay = parseInt(vegassettings.delay);
vega_fade = parseInt(vegassettings.fade);
vega_bg = vegassettings.backgrounds;


vega_att = {
    fade:vega_fade,
    delay:vega_delay,
    backgrounds:[ vega_bg ]
};

jQuery(document).ready(function($){

          jQuery.vegas('slideshow', 
            vega_att
          )
          ('overlay');

        function preloadImg(imgPath) {
          preloadImg = new Image();
          preloadImg.src = imgPath;
        } 

}); //Doc load

这不起作用:::但是如果我发出警报(vega_bg),我会得到以下 vega_bg = {src:'http:// localhost / mocha / wp-content / uploads / 2012/11 / image_01。 jpg'},{src:'http://localhost/lolo-wp/wp-content/uploads/2012/10/image_02.jpg'},

如果我用上面复制的字符串替换vega_att一切正常:::任何帮助都将被赞赏:::

这就是我的HTML :::

中的初始化输出
/* <![CDATA[ */
var vegassettings = {"delay":"5000","fade":"1000","backgrounds":["{ src:'http:\/\/localhost\/lolo-wp\/wp-content\/uploads\/2012\/10\/slider-02.jpg' }","{ src:'http:\/\/localhost\/mocha\/wp-content\/uploads\/2012\/11\/hdr-076.jpg' }"]};
/* ]]> */

我怀疑我的问题与反斜杠有关:::

1 个答案:

答案 0 :(得分:0)

我无法让我的实现工作:::但是我发现另一篇文章有​​一个合理的解决方法,我继续实施这个帖子选项,它的效果非常好Stackoverflow Post