我正在尝试动态加载图像 ::: 在 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}' }";
}
}
本地化我想发送到维加斯的所有属性 :::
// 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
这不起作用 ::: 但是,如果我 alert(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' }"]};
/* ]]> */
我怀疑我的问题与反斜杠有关:::