- var ppt = {
- time : 3000, //每张图变换的时间
- index : 0, //顺序
- imagesArr : [],
- interval : "", //定时器
- numSize : 20,
- init : function () {
- var w = $(".ppt_showbox").width();
- var h = $(".ppt_showbox").height();
- $(".ppt_show").CSS({
- width : w,
- height : h
- });
- var th = h - ppt.numSize - 20;
- var tl = (w - ppt.imagesArr.length * (ppt.numSize + 10)) / 2;
- $(".ppt_tool").css({
- "position" : "absolute",
- "top" : th,
- "left" : tl
- });
- var nums = "";
- for (var i = 1; i < ppt.imagesArr.length + 1; i++) {
- nums += '<a href="javascript:void(0)" class="ppt_num nums_' + i + '">' + i + "</a>";
- }
- $(".ppt_tool").html(nums);
- $(".ppt_num").bind("click", ppt.setIndex);
- $(".ppt_num").css({
- "width" : ppt.numSize,
- "height" : ppt.numSize,
- "border-radius" : ppt.numSize / 2,
- "line-height" : ppt.numSize + "px"
- });
- },
- getImages : function () {
- var i = 0;
- $(".ppt_image").each(function () {
- var obj = {};
- obj.title = $(this).html();
- obj.image = $(this).attr("data");
- obj.src = $(this).attr("href");
- ppt.imagesArr.push(obj);
- });
- },
- setIndex : function () {
- clearInterval(ppt.interval);
- var id = $(this).html();
- id = parseInt(id) - 1;
- $(".ppt_show").attr("src", ppt.imagesArr[id].image);
- setTimeout(function () {
- ppt.interval = setInterval(ppt.change, ppt.time);
- }, ppt.time);
- },
- show : function () {
- ppt.getImages();
- ppt.init();
- ppt.change(); //先执行一次
- ppt.interval = setInterval(ppt.change, ppt.time);
- },
- change : function (src) {
- if (ppt.index >= ppt.imagesArr.length - 1) {
- ppt.index = 0;
- } else {
- ppt.index++;
- }
- var img = ppt.imagesArr[ppt.index];
- var id = ppt.index + 1;
- $(".ppt_show").attr("src", img.image);
- $(".ppt_a").attr("href", img.src);
- $(".ppt_show").attr("title", img.title);
- $(".ppt_num").removeClass("ppt_selected");
- $(".nums_" + id).addClass("ppt_selected");
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1709201513704.html
来源: http://www.codesnippet.cn/detail/1709201513704.html