/* * act.js * --------------------------- * 2013/11/5, Zhang Nan, Create */ String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }; String.prototype.ltrim = function() { return this.replace(/(^\s*)/g, ""); } ; String.prototype.rtrim = function() { return this.replace(/(\s*$)/g, ""); } ; /** * * @param {string} str * @param {array} arr * * @return position or false * */ function arrPos(str, arr) { var i = arr.length; while (i--) { if (arr[i] === str) { return i; } } return false; } /** * * @param {string} id (element id) * @param {string} txt (element tip) * */ function inputFocus(id,txt){ if($('#'+id).val() == txt){ $('#'+id).val(''); } $('#'+id).css('color','black'); } /** * * @param {string} id (element id) * @param {string} txt (element tip) * */ function inputBlur(id,txt){ if(!$('#'+id).val()){ $('#'+id).val(txt); $('#'+id).css('color','#666'); } } /** * * @param {string} id (element id) * @param {string} txt (element tip) * * @return element value or false * */ function checkInput(id,txt){ var obj = $('#'+id); if(!obj.val() || obj.val() == txt){ alert(txt); obj.focus(); return false; }else{ return obj.val(); } } /** * * @param {number} endtime * @param {number} diff * @param {string} dayid (element id) * @param {string} hourid (element id) * @param {string} minid (element id) * @param {string} secid (element id) * * html布局: * 调用:showTimeLimit(endtime, diff, 'day', 'hour', 'min', 'sec'); * */ function showTimeLimit(endtime, diff, dayid, hourid, minid, secid) { var today=new Date(); var timeold=endtime*1000 - today.getTime() - parseInt(diff); var msPerDay=24*60*60*1000; var e_daysold=timeold/msPerDay; var daysold=Math.floor(e_daysold); var e_hrsold=(e_daysold-daysold)*24; var hrsold=Math.floor(e_hrsold); var e_minsold=(e_hrsold-hrsold)*60; minsold=Math.floor((e_hrsold-hrsold)*60); seconds=Math.floor((e_minsold-minsold)*60); // if(daysold < 10) daysold = '0'+daysold; if(hrsold < 10) hrsold = '0'+hrsold; if(minsold < 10) minsold = '0'+minsold; if(seconds < 10) seconds = '0'+seconds; if (daysold >= 0) { $('#'+dayid).text(daysold); $('#'+hourid).text(hrsold); $('#'+minid).text(minsold); $('#'+secid).text(seconds); }else{ $('#'+dayid).text('0'); $('#'+hourid).text('00'); $('#'+minid).text('00'); $('#'+secid).text('00'); } } /** * * @param {number} endtime * @param {number} diff * @param {string} hourid (element id) * @param {string} minid (element id) * @param {string} secid (element id) * * html布局: * 调用:showTimeLimit(endtime, diff, 'day', 'hour', 'min', 'sec'); * */ function showHourLimit(endtime, diff, hourid, minid, secid) { var today=new Date(); var timeold=endtime*1000 - today.getTime() - parseInt(diff); var msPerHour=60*60*1000; var e_hrsold=timeold/msPerHour; var hrsold=Math.floor(e_hrsold); var e_minsold=(e_hrsold-hrsold)*60; minsold=Math.floor((e_hrsold-hrsold)*60); seconds=Math.floor((e_minsold-minsold)*60); if(hrsold < 10) hrsold = '0'+hrsold; if(minsold < 10) minsold = '0'+minsold; if(seconds < 10) seconds = '0'+seconds; if (hrsold >= 0) { $('#'+hourid).text(hrsold); $('#'+minid).text(minsold); $('#'+secid).text(seconds); }else{ $('#'+hourid).text('00'); $('#'+minid).text('00'); $('#'+secid).text('00'); } } //文字向上滑动 /** * * @param {Object} $ * * html布局:
* 调用:$("#succ_person").stepScroll({line:1, speed:500, timer:3000}); * */ (function($){ $.fn.extend({ stepScroll:function(opt,callback){ if(!opt) var opt = {}; var table = this.eq(0).find("ul:last"); var lineH = table.find("li:first").height(); var line = opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10); var speed = opt.speed?parseInt(opt.speed,10):500; var timer = opt.timer?parseInt(opt.timer,10):3000; line = line==0?1:line; var upHeight= 0-line*lineH; scrollUp = function(){ table.animate({ marginTop:upHeight },speed,function(){ for(i=1; i<=line; i++){ table.find("li:first").appendTo(table); } table.css({marginTop:0}); }); } table.hover(function(){ clearInterval(timerID); },function(){ timerID = setInterval("scrollUp()",timer); }); timerID = setInterval("scrollUp()",timer); } }) })(jQuery); //文字向左滑动 (function($){ $.fn.extend({ leftScroll:function(opt,callback){ if(!opt) var opt = {}; var table = this.eq(0).find("ul:last"); var lineH = table.find("li:first").width(), line = opt.line?parseInt(opt.line,10):parseInt(this.width()/lineH,10), speed = opt.speed?parseInt(opt.speed,10):500, timer = opt.timer?parseInt(opt.timer,10):3000; line = line==0?1:line; var upHeight= 0-line*lineH; scrollLeft = function(){ table.animate({ marginLeft:upHeight },speed,function(){ for(i=1; i<=line; i++){ table.find("li:first").appendTo(table); } table.css({marginLeft:0}); }); } table.hover(function(){ clearInterval(timerID); },function(){ timerID = setInterval("scrollLeft()",timer); }); timerID = setInterval("scrollLeft()",timer); } }); })(jQuery); /** * * @param {number} minHeight * @param {number} marginleft * @param {string} img (img path) * * 调用注意::兼容ie6需要在css中定义如下样式 * #gotoTop{ _position:absolute; _top:expression(documentElement.scrollTop + 500); _left:630px; margin-left: 520px; cursor: pointer; display:none; } */ function gotoTop(minHeight, marginleft, img){ function isIE6(){ if($.browser.msie && $.browser.version == '6.0'){ return true; }else{ return false; } } isIE6 = isIE6(); if(typeof(img) == 'undefined'){ img = '返回顶部'; }else{ img = ''; } var gotoTop_html = '
'+img+'
'; $("body").append(gotoTop_html); if (!isIE6) { $('#gotoTop').css({ 'top': '75%', 'left': '50%', 'position': 'fixed', 'margin-left': marginleft+'px', 'cursor': 'pointer', 'display': 'none' }); } $("#gotoTop").click(function(){ $('html,body').animate({scrollTop:0},700); }); $(window).scroll(function(){ var s = $(window).scrollTop(); if( s > minHeight){ $("#gotoTop").fadeIn(100); }else{ $("#gotoTop").fadeOut(200); }; }); } function gotoTop2(minHeight, img){ img = ''; var gotoTop_html = '
'+img+'
'; $("body").append(gotoTop_html); $('#gotoTop').css({ 'width': '71px', 'height': '71px', 'top': '-1000px', 'right': '-1000px', 'position': 'absolute', 'cursor': 'pointer', 'display': 'none', 'zIndex': '50' }); $("#gotoTop").click(function(){ $('html,body').animate({scrollTop:0},700); }); $(window).scroll(function(){ var s = $(window).scrollTop(); if( s > minHeight){ $("#gotoTop").fadeIn(100); }else{ $("#gotoTop").fadeOut(200); }; }); initgoTop(); } function initgoTop(){ gotop_obj = document.getElementById('gotoTop'); if(gotop_obj){ movegoTop(); $(window).scroll(movegoTop); $(window).resize(movegoTop); } } function movegoTop() { scrollTop = document.documentElement.scrollTop==0?document.body.scrollTop:document.documentElement.scrollTop; scrollLeft = document.documentElement.scrollLeft==0?document.body.scrollLeft:document.documentElement.scrollLeft; gotop_obj.style.top = (scrollTop+document.documentElement.clientHeight-gotop_obj.clientHeight-70) + "px"; gotop_obj.style.left = (scrollLeft+document.documentElement.clientWidth-gotop_obj.clientWidth-10) + "px"; } function left_nav(minHeight){ $(window).scroll(function(){ var s = $(window).scrollTop(); if( s > minHeight){ $("#left").fadeIn(100); }else{ $("#left").fadeOut(200); }; }); } /** * * @param {number} speed * @param {string} allid (element id) * @param {string} itemid (element id) * * html布局:
内容
* 调用:textScroll(30, 'all', 'item1'); */ function textScroll(speed, allid, itemid){ var all = document.getElementById(allid); var item1 = document.getElementById(itemid); var item2 = document.createElement('div'); all.appendChild(item2); item2.innerHTML = item1.innerHTML; var scrollTop = 1; var MyMar = setInterval(Marquee, speed); all.onmouseover = function(){ clearInterval(MyMar); }; all.onmouseout = function(){ MyMar = setInterval(Marquee, speed); }; function Marquee(){ if (item2.offsetHeight - all.scrollTop <= 0 || scrollTop == all.scrollTop){ all.scrollTop -= item1.offsetHeight; }else { scrollTop = all.scrollTop; all.scrollTop++; } } } function getSwf(src, width, height, bgcolor, wmode) { var isIE6 = $.browser.msie && $.browser.version == '6.0'?true:false; var template = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + ''; var html = template.replace(/\{\$url\}/g, src); bgcolor = bgcolor==null?'#000000':bgcolor; wmode = wmode==null?'opaque':wmode; html = html.replace(/\{\$width\}/g, width); html = html.replace(/\{\$height\}/g, height); if (!isIE6) { html = html.replace(/\{\$wmode\}/g, wmode); } html = html.replace(/\{\$bgcolor\}/g, bgcolor); return html; } /** * * @param {string} element * @param {array} arr * * html布局:
* 调用:switch('.tab li a', arr); arr = {"horse":"swf/horse.swf","ox":"swf/ox.swf","dragon":"swf/dragon.swf"}; * */ function switchSwf(element, arr, callback){ function isIE6(){ if($.browser.msie && $.browser.version == '6.0'){ return true; }else{ return false; } } isIE6 = isIE6(); var template = '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + ''; $(element).hover(function(){ if ($(this).attr('class') != 'select') { $(this).parent().siblings("li").children().removeClass("select"); var id = $(this).parent("li").attr("id"); var html = template.replace(/\{\$url\}/g, arr[id]); var object = $(this).parent().parent().parent().children('#content').children('object'); var width = object.attr('width'); var height = object.attr('height'); var wmode = 'opaque'; var bgcolor = '#000000'; object.children('param').each(function(){ if ($(this).attr('name').toLowerCase() == 'wmode') { wmode = $(this).attr('value'); } if ($(this).attr('name').toLowerCase() == 'bgcolor') { bgcolor = $(this).attr('value'); } }); html = html.replace(/\{\$width\}/g, width); html = html.replace(/\{\$height\}/g, height); if (!isIE6) { html = html.replace(/\{\$wmode\}/g, wmode); } html = html.replace(/\{\$bgcolor\}/g, bgcolor); $(this).parent().parent().siblings('#content').html(html); $(this).addClass("select"); if(typeof(callback)!='undefined') { try{ callback($(this), $(this).parent().parent().siblings('#content')); }catch(e){ alert(e); } } } }); } function switchPic(element, arr, callback){ $(element).hover(function(){ if ($(this).attr('class') != 'select') { $(this).parent().siblings("li").children().removeClass("select"); var id = $(this).parent("li").attr("id"); html = ''; $(this).parent().parent().siblings('#content').html(html); $(this).addClass("select"); if(typeof(callback)!='undefined') { try{ callback($(this), $(this).parent().parent().siblings('#content')); }catch(e){ alert(e); } } } }); } /** * 有待更新.....(1修改布局、2增加样式、3调整参数允许传数组仿照其本来函数参数格式、4注意命名) * @param {number} changeWidth * @param {string} outerId * @param {string} innerId * @param {string} referInnerId * @param {string} liClassPrefix (element class prefix. eg:class="ss0" => ss) * @param {string} pagerId * @param {string} nextId * @param {string} prevId * * html布局: *
* *
*
* * *
* * 调用:pagerSlide('outerImg', 'innerImg', 'innerImg2', 'prefix', 'pager', 'snext', 'sprev'); * */ function pagerSlide(changeWidth, outerId, innerId, referInnerId, liClassPrefix, pagerId, nextId, prevId){ //页签 var nums = []; var st = ''; $$(pagerId).innerHTML = ''; var imgNum = $('#'+referInnerId+' li').length; for(var i = 0; i < imgNum; addNum(i++)){} function addNum(i){ var num = $$(pagerId).appendChild(document.createElement("li")); num.innerHTML = i+1; num.onmouseover = function(){ num.className = "selected"; st.Run(i); }; nums[i] = num; } //新建st对象 st = new SlideTrans(outerId, innerId, imgNum, { Vertical:false, Change:changeWidth, Auto:true, Duration: 30,//滑动持续时间 Time: 10,//滑动延时 Straight: true, Tween: Tween.Straight.easeOut, //tween算子 onStart: function(){ forEach(nums, function(o, i){ //页签随着 o.className = st.Index == i ? "selected" : ""; }); //找到前一个和现在这个 var nowIndex, beforeIndex; var objs = $('#'+referInnerId+' li'); objs.each(function(idx2){ if(idx2 == st.Before){ beforeIndex = idx2; } if(idx2 == st.Index) { nowIndex = idx2; } }); //提取出来刚才的两个放在要显示的位置 if (beforeIndex != nowIndex) { var referObj = $('#'+referInnerId+' li').eq(nowIndex); $('#'+innerId+' .'+liClassPrefix + beforeIndex).siblings("li").remove(); if (beforeIndex < nowIndex) { $('#'+innerId).append(referObj.clone()); }else{ $('#'+innerId).prepend(referObj.clone()); } var innerObj = $('#'+innerId+' .'+liClassPrefix+nowIndex); innerObj.children('img').lazyload().trigger("appear"); innerObj.children('.lazy').lazyload().trigger("appear"); } } }); //左右切换 $$(nextId).onclick = function(){ st.Next(); }; $$(prevId).onclick = function(){ st.Previous(); }; st.Run(); }