看看这里的首页滑块:
http://wildwoodtreeservices.wordpress.redcow.ca/
正如您所看到的,它的功能是从图像转换到图像,并且与相应图像匹配的圆圈会变为不同的颜色……我唯一的问题是它不平滑。图像以丑陋的方式加载,让您在一瞬间看到背景图像而不是图像本身。
有什么方法可以使淡入/淡出过渡平滑,因此他们看不到任何背景?我是否必须在页面加载时缓存所有 11 个图像?
提前致谢
我的 JS:
<script>
var sliderpics = [];
sliderpics[0] = "/wp-content/themes/REDCOW-WP/slider1.jpg";
sliderpics[1] = "/wp-content/themes/REDCOW-WP/slider2.jpg";
sliderpics[2] = "/wp-content/themes/REDCOW-WP/slider3.jpg";
sliderpics[3] = "/wp-content/themes/REDCOW-WP/slider4.jpg";
sliderpics[4] = "/wp-content/themes/REDCOW-WP/slider5.jpg";
sliderpics[5] = "/wp-content/themes/REDCOW-WP/slider6.jpg";
sliderpics[6] = "/wp-content/themes/REDCOW-WP/slider7.jpg";
sliderpics[7] = "/wp-content/themes/REDCOW-WP/slider8.jpg";
sliderpics[8] = "/wp-content/themes/REDCOW-WP/slider9.jpg";
sliderpics[9] = "/wp-content/themes/REDCOW-WP/slider10.jpg";
sliderpics[10] = "/wp-content/themes/REDCOW-WP/slider11.jpg";
var currentImage = 0;
var currentCircle = 0;
function changeSliderImage() {
currentImage++;
currentCircle++;
if(currentImage > 10) currentImage = 0;
if(currentCircle > 10) currentCircle = 0;
$("#sliderpic").fadeOut(200, function() {
$(this).attr("src",sliderpics[currentImage]);
$("#circle" + currentCircle).attr("src","/wp-content/themes/REDCOW-WP/circle_active.png");
$("#circle" + (currentCircle - 1)).attr("src","/wp-content/themes/REDCOW-WP/circle_inactive.png");
if(currentCircle == 0){
$("#circle10").attr("src","/wp-content/themes/REDCOW-WP/circle_inactive.png");
}
});
$("#sliderpic").fadeIn(200);
setTimeout(changeSliderImage, 5000);
}
$(document).ready(function($) {
setTimeout(changeSliderImage, 5000);
});
</script>