var Top_Data = function(option){ var sets = { div_id: 'index_topbox', ul_id: 'index_topbox_ul' }; $.extend(sets, option); var twidth = parseInt($("#" + sets.div_id).width()); var theight = parseInt($("#" + sets.div_id).height()); $("body").append('
'); $("#index_topbox_bt").css({ position : 'absolute', width : twidth - 10, height : 20, top : parseInt($("#" + sets.div_id).offset().top) + theight - 30, left : $("#" + sets.div_id).offset().left, 'text-align': 'center', padding : '5px' }); $("body").append(''); $("body").append(''); $("#top_left_bt").css({ left : $("#index_topbox").offset().left, top : $("#index_topbox").offset().top + theight / 2 - 26, position : 'absolute', cursor : 'pointer' }).click(function(){ var indexWidth= $("#index_topbox").innerWidth(); if(!$("#index_topbox_bt").find(".top_pic_focus").prev().attr('class')){ $("#index_topbox_ul").prepend($("
  • ").append($("#index_topbox_ul li:last").html())); $("#index_topbox_ul").css({left : "-"+indexWidth+"px"}); $("#" + sets.ul_id).animate({left : "0px"},function (){ $("#index_topbox_ul").find("li:first").remove(); $("#index_topbox_ul").css({left : $("#index_topbox_bt").find("span:last").attr('leftval')+"px"}); }); $("#index_topbox_bt").find('.move_bt').attr('class', 'move_bt top_pic_default'); $("#index_topbox_bt").find("span:last").attr('class', 'move_bt top_pic_focus'); } else{ $("#index_topbox_bt").find(".top_pic_focus").prev().trigger('click'); }; }); $("#top_right_bt").css({ left : $("#index_topbox").offset().left + twidth - 53, top : $("#index_topbox").offset().top + theight / 2 - 26, position : 'absolute', cursor : 'pointer' }).click(function(){ var indexWidth= $("#index_topbox").innerWidth(); if(!$("#index_topbox_bt").find(".top_pic_focus").next().attr('class')){ $("#index_topbox_ul").append($("
  • ").append($("#index_topbox_ul li:first").html())); $("#" + sets.ul_id).animate({left :parseInt($(".top_pic_focus").attr('leftval'))-indexWidth},function (){ $("#index_topbox_ul").css({left : "0px"}); $("#index_topbox_ul").find("li:last").remove(); }); $("#index_topbox_bt").find('.move_bt').attr('class', 'move_bt top_pic_default'); $("#index_topbox_bt").find(".move_bt:eq(0)").attr('class', 'move_bt top_pic_focus'); } else{ $("#index_topbox_bt").find(".top_pic_focus").next().trigger('click'); } }); //縮放視窗重新定位 $(window).resize(function(){ $("#index_topbox_bt").css({ top : parseInt($("#" + sets.div_id).offset().top) + theight - 30, left : $("#" + sets.div_id).offset().left }); $("#top_left_bt").css({ left : $("#index_topbox").offset().left, top : $("#index_topbox").offset().top + theight / 2 - 26, position : 'absolute', cursor : 'pointer' }); $("#top_right_bt").css({ left : $("#index_topbox").offset().left + twidth - 53, top : $("#index_topbox").offset().top + theight / 2 - 26, position : 'absolute', cursor : 'pointer' }); }); var i = 0; $("#" + sets.div_id).find("ul li").each(function(){ var left = - (i * twidth), c = ''; i++; (i == 1)? c = 'top_pic_focus': c = 'top_pic_default'; $("#index_topbox_bt").append(' '); }); var topIntvalID = ''; $(".move_bt").click(function(){ $("#index_topbox_bt").find('.move_bt').attr('class', 'move_bt top_pic_default'); $("#" + sets.ul_id).animate({left :$(this).attr('leftval')}); $(this).attr('class', 'move_bt top_pic_focus'); }); $("#index_topbox_ul, #top_left_bt, #top_right_bt").hover( function(){ clearInterval(topIntvalID); }, function (){ topIntvalID = setInterval("Top_Data.auto('"+sets.ul_id+"')", 5000); }); topIntvalID = setInterval("Top_Data.auto('"+sets.ul_id+"')", 5000); }; Top_Data.auto = function(ulId){ var indexWidth= $("#index_topbox").innerWidth(); if(!$("#index_topbox_bt").find(".top_pic_focus").next().attr('class')){ $("#index_topbox_ul").append($("
  • ").append($("#index_topbox_ul li:first").html())); $("#" + ulId).animate({left :parseInt($(".top_pic_focus").attr('leftval'))-indexWidth},function (){ $("#index_topbox_ul").css({left : "0px"}); $("#index_topbox_ul").find("li:last").remove(); }); $("#index_topbox_bt").find('.move_bt').attr('class', 'move_bt top_pic_default'); $("#index_topbox_bt").find(".move_bt:eq(0)").attr('class', 'move_bt top_pic_focus'); } else{ $("#index_topbox_bt").find(".top_pic_focus").next().trigger('click'); } }; /* .top_pic_focus{ margin:0px 3px 0px 3px; padding:0px 4px 0px 4px; border:1px solid #242424; color:#FFF; background:#242424; font-size:13px; } .top_pic_default{ margin:0px 3px 0px 3px; padding:0px 4px 0px 4px; border:1px solid #CCC; color:#FFF; background:#949494; font-size:13px; } */