首页轮播图片原来采用Flash插件,因浏览器升级导致在新浏览器下该区域无图片显示。为此,重新编写了代码,采用JQuery插件,通过JS控制图片轮播,支持HTML5标准。
有关代码如下:
function initscroll() {
$(".paging").show();
$(".paging a:first").addClass("active");
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;
$(".image_reel").css({'width' : imageReelWidth});
$(".image_reel img").css({'width' : imageWidth});
$(".window").css({'width' : imageWidth});
$(".window").css({'height' : $(".image_reel img:first").height()});
rotate = function(){
var triggerID = $(".active").attr("rel") - 1; //Get number of times to slide
var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide
//Slider Animation
$(".image_reel").animate({
left: -image_reelPosition
}, 500 );
};
//Rotation + Timing Event
rotateSwitch = function(){
play = setInterval(function(){
var triggerID = $(".active").attr("rel") - 1;
$(".paging a").removeClass("active");
if ( triggerID === 0) { //If paging reaches the end...
$(".paging a").last().addClass("active");
}
else{
$(".paging a[rel$="+triggerID+"]").addClass("active");
}
rotate(); //Trigger the paging and slider function
}, 6000); //Timer speed
};
rotateSwitch(); //Run function on launch
//On Hover
$(".image_reel a").hover(function() {
clearInterval(play); //Stop the rotation
}, function() {
rotateSwitch(); //Resume rotation
});
//On Click
$(".paging a").click(function() {
$(".paging a").removeClass("active");
$(this).addClass("active");
//Reset Timer
clearInterval(play); //Stop the rotation
rotate();
rotateSwitch(); // Resume rotation
return false; //Prevent browser jump to link anchor
});
}
$(document).ready(function(){
initscroll();
});
图片轮播器支持5张图片显示。