【发布时间】:2014-08-27 07:34:22
【问题描述】:
我在我的单页上使用 iosslider。 我需要从 '.wp-pic' 收集所有 img src 并将它们放到滑块背景 url 中。 所以我有什么:
带有 WP 图片的滑块框架和 DIV:
<div class='my-slider large-9 columns'>
<div class='sliderContainer'>
<div class='iosSlider'>
<div class='slider'>
</div>
</div>
</div>
</div><!--/.slider-->
<div class='wp-pic'>
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
/* SLIDER SETTINGS
=============================================*/
.sliderContainer{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
}
.iosSlider{
position: relative;
top: 0;
left: 0;
overflow: hidden;
width: 100%;
height: 100%;
}
.iosSlider .slider{
width: 100%;
height: 100%;
}
.iosSlider .slider .item{
float: left;
width: 100%;
height: 100%;
}
// REMOVE PICTURES PUSHED BY WP AND PUT THEM TO THE IOSSLIDER
$('.wp-pic').find('img').each(function(){
var photoSrc = $(this).attr('src'),
photoImg = '<img src="' + photoSrc + '">',
numbClass = Math.round(Math.random() * 15);
$('.slider').append('<div class="item photo-template' + numbClass + '">' + photoImg + '</div>');
$('.wp-pic').remove();
});
$('.item').find('img').each(function(){
var x = $(this).attr('src');
$('.slider').find('div:contains(photo-template)').each(function(){
$(this).css({
'background-image' :'url(' + x + ')',
'background-size' :'contain',
'background-position':'center',
'background-repeat' :'no-repeat'
});
});
$(this).remove();
});
如何选择每个类的“照片模板”并将其放置在背景收集的 src 中?
【问题讨论】:
标签: javascript jquery css wordpress jquery-ui-slider