我正试图获得以下信息:
通过使用FlexSlider(http://www.woothemes.com/flexslider/),我想根据加载的幻灯片获得不同的背景颜色。
我做了这样的事:
<?php
$bg1="red";
$bg2="blue";
?>
然后,在我的flexSlider jQuery中:
<script type="text/javascript">
$(window).load(function(){
$('.flexslider').flexslider({
animation: "slide",
start: function(slider){
$('body').removeClass('loading');
},
before: function(slider) {
var current = slider.currentSlide;
$('#container').css("background-color","<?php echo $bg?>+current");
},
});
});
</script>
我试图从php变量中检索值,并将它们放入容器的css中。好的,这里是我被卡住的地方,如果是第一张幻灯片,我如何让它加载bg1,如果是第二张幻灯片,如何加载bg2,依此类推?
我想我可以做一些类似电流的事情,但它不起作用。。。我相信这很容易-
非常感谢您的帮助!
谢谢!
我通过使用Flexslider(它有一些API)实现了我所需要的功能,因此我的最终代码如下:
<script type="text/javascript">
$(window).load(function(){
$('.flexslider').flexslider({
animation: "fade",
slideshow: true, //Boolean: Animate slider automatically
slideshowSpeed: 6000,
animationSpeed: 300,
start: function(slider){
$('body').removeClass('loading');
},
before: function(slider) {
animate = 'bg'+slider.animatingTo
$('#container').addClass(animate, 1000);
current = 'bg'+slider.currentSlide;
$('#container').removeClass(current);
}
});
});
</script>
这是未经测试的,但是快速浏览一下flexslider.js我相对有信心你可以在第427行找到的动画slider.flex函数中实现背景滚动。这假设您只在一个位置使用滑块(或者至少可以对滑块的每个实例进行背景更改)。
此外,如果你的滑块是在一个固定的时间间隔,我想建议使用CSS关键帧动画循环通过你的2个背景选项。下面是一个小示例,假设间隔为10秒:
@keyframes bgpulse {
0% {background-color: #FFFFFF;}
100% {background-color: #000000;}
}
@-webkit-keyframes bgpulse {
0% {background-color: #FFFFFF;}
100% {background-color: #000000;}
}
/*Body Styles*/
body {
animation: bgpulse 10s infinite alternate;
-webkit-animation: bgpulse 10s infinite alternate;
}
使用模数,如。。
$('#container').css("background-color",(current%2==0)?"<?php echo $bg1?>":"<?php echo $bg2?>");