一些通用的js工具類,新增自定義外掛
阿新 • • 發佈:2019-01-02
/** * 通用工具元件 對原有的工具進行封裝,自定義某方法統一處理<br> * ^_^ * * Author: em.D * Date: 2016-05-17 * Version: 0.0.1 */ function send_http() { $(selector)..get(URL, data, function(data,status,xhr) {}, dataType); $(selector).post(URL, data, function(data,status,xhr) {}, dataType) $(selector).getJSON(url, data, function(data,status,xhr) {}); } function all_ajax() { $.ajax({ url: "xx.do", type: "post", data: {}, //async: false, //設定為同步,預設為非同步(一般不需要) cache: false, dataType: "json", //password: "", timeout: 1000 * 10, // 毫秒 beforeSend: function(XMLHttpRequest) { // ShowLoading(); }, success: function(data) { if (data != null) { if ("success" == data.result) { // TODO } else { // $.messager.alert("系統提示", "操作失敗,請重試", "info"); } // console.log("result = " + data.result + ",msg=" + // data.msg);//IE不支援console輸出 } else { // $.messager.alert("系統提示","返回結果為空!","info"); } }, complete: function(XMLHttpRequest, textStatus) { // alert("textStatus="+textStatus); // closeLoading();//關閉進度條 }, error: function(XMLHttpRequest, textStatus, errorThrown) { // closeLoading();//關閉進度條 if ("error" == textStatus) { // $.messager.alert("系統提示", "伺服器未響應,請稍候再試", "info"); } else { // $.messager.alert("系統提示", "請求失敗,textStatus="+textStatus, // "info"); } }, }); } ; (function() { $.extend({ log: function(message) { var now = new Date(), y = now.getFullYear(), m = now.getMonth() + 1, // !JavaScript中月分是從0開始的 d = now.getDate(), h = now.getHours(), min = now.getMinutes(), s = now.getSeconds(), time = y + '/' + m + '/' + d + ' ' + h + ':' + min + ':' + s; console.log(time + ' My Log: ' + message); } }); //$.log('initializing...'); // 呼叫 em = {}; em.ajax = (function(params) { var pp = { error: function(XMLHttpRequest, textStatus, errorThrown) { console.log("資料請求異常,異常狀態:" + XMLHttpRequest.status); } }; $.extend(pp, params); $.ajax(pp); }); /** * 表單提交 * @param from 表單ID * @param params ajax引數 * * @author em.D */ em.ajaxSubmit = (function(form, params) {// form 表單ID. params ajax引數 var pp = { // clearForm: true, // resetForm: true, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log("資料請求異常,異常狀態:" + XMLHttpRequest.status); } }; $.extend(pp, params); $(form).ajaxSubmit(pp); }); CommonUtil = { /** * ajax同步請求 返回一個html內容 dataType=html. 預設為html格式 如果想返回json. * CommonUtil.ajax(url, data, "json") * * @author em.D */ ajax: function(url, data, dataType) { if (!CommonUtil.notNull(dataType)) { dataType = "html"; } var html = '沒有結果!'; // 所以AJAX都必須使用em.ajax..這裡經過再次封裝,統一處理..同時繼承ajax所有屬性 if (url.indexOf("?") > -1) { url = url + "&_t=" + new Date(); } else { url = url + "?_t=" + new Date(); } em.ajax({ type: "post", url: url, data: data, dataType: dataType, // 這裡的dataType就是返回回來的資料格式了html,xml,json async: false, cache: false, // 設定是否快取,預設設定成為true,當需要每次重新整理都需要執行資料庫操作的話,需要設定成為false traditional: true, // struts2陣列引數異常 //contentType: "application/json", success: function(data) { html = data; } }); return html; }, ajaxAsync: function(type, url, param, dataType, callback) { if (!CommonUtil.notNull(type)) { type = "get"; } if (!CommonUtil.notNull(dataType)) { dataType = "html"; } if (url.indexOf("?") > -1) { url = url + "&_t=" + new Date(); } else { url = url + "?_t=" + new Date(); } //(callback && typeof(callback)==="function") && callback(); if(!(typeof callback == "function")) { callback = function(data) { $.log("ajaxAsync執行失敗,callback不是函式!"); } } em.ajax({ type: type, url: url, data: param, dataType: dataType, async: true, cache: false, success: callback }); }, /** * 獲取位址列引數 */ getURLParam: function(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var url = window.location.search.substring(1).match(reg); if (url != null) { return decodeURI(url[2]); // decodeURI | unescape } return null; }, /** * 判斷某物件不為空..返回true 否則 false * * @author em.D */ notNull: function(obj) { if (obj === null) { return false; } else if (obj === undefined) { return false; } else if (obj === "undefined") { return false; } else if (obj === "") { return false; } else if (obj === "[]") { return false; } else if (obj === "{}") { return false; } else { return true; } }, /** * 判斷某物件不為空..返回obj 否則 "" * * @author em.D */ notEmpty: function(obj) { if (obj === null) { return ""; } else if (obj === undefined) { return ""; } else if (obj === "undefined") { return ""; } else if (obj === "") { return ""; } else if (obj === "[]") { return ""; } else if (obj === "{}") { return ""; } else { return obj; } }, /** * 判斷引數(String,Array,Object)是否為undefined或者值為空, true: 為空 */ isEmptyValue: function(value) { var type; if(value == null) { // 等同於 value === undefined || value === null return true; } type = Object.prototype.toString.call(value).slice(8, -1); switch(type) { case 'String': return !$.trim(value); case 'Array': return !value.length; case 'Object': return $.isEmptyObject(value); // 普通物件使用 for...in 判斷,有 key 即為 false default: return false; // 其他物件均視作非空 } }, /** * 阻止事件冒泡 */ preventBubble: function() { /* * return false 在事件的處理中,可以阻止預設事件和冒泡事件。 * event.preventDefault()在事件的處理中,可以阻止預設事件但是允許冒泡事件的發生。 * event.stopPropagation()在事件的處理中,可以阻止冒泡但是允許預設事件的發生。 */ var e = arguments.callee.caller.arguments[0] || event; // 若省略此句,下面的e改為event,IE執行可以,但是其他瀏覽器就不相容 if (e && e.stopPropagation) { // this code is for Mozilla and Opera e.stopPropagation(); } else if (window.event) { // this code is for IE window.event.cancelBubble = true; } }, loadingImg: function() { var html = '<div class="alert alert-warning">' + '<button type="button" class="close" data-dismiss="alert">' + '<i class="ace-icon fa fa-times"></i></button><div style="text-align:center">' //+ '<img src="' + rootPath + '/images/loading.gif"/><div>' + '<img src="images/loading.gif"/><div>' + '</div>'; return html; }, /** * html標籤轉義 * * @author em.D */ htmlspecialchars: function(str) { var s = ""; if (str.length == 0) return ""; for (var i = 0; i < str.length; i++) { switch (str.substr(i, 1)) { case "<": s += "&lt;"; break; case ">": s += "&gt;"; break; case "&": s += "&amp;"; break; case " ": if (str.substr(i + 1, 1) == " ") { s += " &nbsp;"; i++; } else s += " "; break; case "\"": s += "&quot;"; break; case "\n": s += ""; break; default: s += str.substr(i, 1); break; } } }, /** * in_array判斷一個值是否在陣列中 */ in_array: function(array, string) { for (var s = 0; s < array.length; s++) { thisEntry = array[s].toString(); if (thisEntry == string) { return true; } } return false; }, formatNum: function(num) { var patt = new RegExp(/(\+|-)?(\d+)(\.\d+)?/g); if (!patt.test(num)) { return num; } var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3; var re = new RegExp("(\\d)(\\d{3})(,|$)"); while (re.test(b)) { b = b.replace(re, "$1,$2$3"); } return a + "" + b + "" + c; }, setLstorageVal: function(key, value) { window.localStorage['emSsnsrg_' + key] = value; }, getLstorageVal: function(key) { if(window.localStorage['emSsnsrg_'+key]) return window.localStorage['emSsnsrg_' + key]; else if(window.localStorage['emSsnsrg_' + key]) return window.localStorage['emSsnsrg_' + key]; else return ""; }, clearLstorageVal: function(key) { if(key) window.localStorage.removeItem('emSsnsrg_' + key); else window.localStorage.clear(); }, setStorageVal: function(key, value) { window.sessionStorage['emSsnsrg_'+key] = value; }, getStorageVal: function(key) { if(sessionStorage['emSsnsrg_' + key]) return sessionStorage['emSsnsrg_' + key]; else if(window.sessionStorage['emSsnsrg_' + key]) return window.sessionStorage['emSsnsrg_' + key]; else return ""; }, clearStorageVal: function(key) { if(key) window.sessionStorage.removeItem('emSsnsrg_' + key); else window.sessionStorage.clear(); } }; })(); // 表單json格式化方法……不使用&拼接 (function($) { var my_blink_plug_name = "myblink"; /** * * $("div").myblink({ interval: 300, // 閃動間隔時間,預設為100 blink_count: 3, // 最大閃動次數,0表示無限 before_blink: function (obj){ // 閃動前回調方法 $(obj).css({color: "red"}); }, after_blink: function (obj){ // 閃動結束回撥方法 $(obj).css({color: "black"}); } }); $("div").fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100); */ $.fn[my_blink_plug_name] = function(options) { var defaults = { interval: 100, blink_count: 0, before_blink: function(obj) {}, after_blink: function(obj) {} }; this.settings = $.extend({}, defaults, options); var _this = this; var c = 0; _this.settings.before_blink(_this); var myVar = setInterval(function() { if (_this.css("visibility") == "visible") { _this.css('visibility', 'hidden'); } else { _this.css('visibility', 'visible'); if(_this.settings.blink_count > 0) { c ++; if(c == _this.settings.blink_count){ clearInterval(myVar); _this.settings.after_blink(_this); } } } }, _this.settings.interval); return this; }; $.fx.step["backgroundPosition"] = function(fx) { if (typeof fx.end == 'string') { fx.start = getBgPos(fx.elem); // fx.end原本是一個string,這裡將它轉換成陣列,就不會再進入這個if,也方便我們下面的計算 // 例 "0px -21px" fx.end = [parseFloat(fx.end.split(" ")[0]), parseFloat(fx.end.split(" ")[1])]; } // 這裡fx.pos是根據傳入的時間引數,從0到1變化的浮點數 var nowPosX = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit; var nowPosY = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit; fx.elem.style.backgroundPosition = nowPosX + ' ' + nowPosY; /** * 獲取backgroundPosition陣列[top, left],沒有單位 */ function getBgPos(elem) { var top = 0.0; var left = 0.0; if ($(elem).css("backgroundPosition")) { // 例 "0px -21px" top = parseFloat($(elem).css("backgroundPosition").split(" ")[0]); left = parseFloat($(elem).css("backgroundPosition").split(" ")[1]); } else { top = parseFloat($(elem).css("backgroundPositionX")); left = parseFloat($(elem).css("backgroundPositionY")); } return [top, left]; } }; /* end */ /** * <pre> * 自定義jquery函式,完成將form 資料轉換為 json格式 * * // 將 form 資料轉換 json格式 * var params = $(&quot;#searchForm&quot;).serializeJson(); &lt;pre&gt; * * @author em.D * */ $.fn.serializeJson = function() { var serializeObj = {}; // 目標物件 var array = this.serializeArray(); // 轉換陣列格式 // var str=this.serialize(); $(array).each(function() { // 遍歷陣列的每個元素 {name: xx , value: xxx} if (serializeObj[this.name]) { // 判斷物件中是否已經存在 name,如果存在name if ($.isArray(serializeObj[this.name])) { serializeObj[this.name].push(this.value); // 追加一個值 hobby: ['音樂','體育'] } else { // 將元素變為 陣列 ,hobby: ['音樂','體育'] serializeObj[this.name] = [serializeObj[this.name], this.value ]; } } else { serializeObj[this.name] = this.value; // 如果元素name不存在,新增一個屬性 name:value } }); return serializeObj; }; /** * 限制只能輸入數字和字母 */ $.fn.onlyNumAlpha = function() { $(this).keypress(function(event) { var eventObj = event || e; var keyCode = eventObj.keyCode || eventObj.which; if ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122)) return true; else return false; }).focus(function() { this.style.imeMode = 'disabled'; }).bind("paste", function() { var clipboard = window.clipboardData.getData("Text"); if (/^(\d|[a-zA-Z])+$/.test(clipboard)) return true; else return false; }); }; $.fn.rowspan = function(colIdx) { return this.each(function() { var that; $('tr', this).each(function(row) { $('td:eq(' + colIdx + ')', this).each(function(col) { if ($(this).html() == $(that).html()) { rowspan = $(that).attr("rowSpan"); if (rowspan == undefined) { $(that).attr("rowSpan", 1); rowspan = $(that).attr("rowSpan"); } rowspan = Number(rowspan) + 1; $(that).attr("rowSpan", rowspan); // do your action for the colspan cell here $(this).hide(); // .remove(); // do your action for the old cell here } else { that = this; } that = (that == null) ? this: that; // set the that if not already set }); }); }); }; /** * [numFormat 數字新增千位分隔符] * @return {[String]} [123,123,123] */ Number.prototype.numFormat = function() { if (!CommonUtil.notNull(this)) { return "0"; } var patt = new RegExp(/(\+|-)?(\d+)(\.\d+)?/g); if (!patt.test(this)) { return this; } var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3; var re = new RegExp("(\\d)(\\d{3})(,|$)"); while (re.test(b)) { b = b.replace(re, "$1,$2$3"); } return a + "" + b + "" + c; }; String.prototype.trim = function() { return this.replace(/^\s+/, '').replace(/\s+$/, ''); }; String.prototype.numFormat = function() { if (!CommonUtil.notNull(this)) { return "0"; } var patt = new RegExp(/(\+|-)?(\d+)(\.\d+)?/g); if (!patt.test(this)) { return this; } var a = RegExp.$1, b = RegExp.$2, c = RegExp.$3; var re = new RegExp("(\\d)(\\d{3})(,|$)"); while (re.test(b)) { b = b.replace(re, "$1,$2$3"); } return a + "" + b + "" + c; }; /** * [format 對Date的擴充套件,將 Date 轉化為指定格式的String] * // 年(y)可以用 1-4 個佔位符,毫秒(S)只能用 1 個佔位符(是 1-3 位的數字), 月(M)、日(d)、小時(h)、分(m)、秒(s)、季度(q) 可以用 1-2 個佔位符 * * @param {[string]} format [yyyy-MM-dd hh:mm:ss:S q] * @return {[string]} [格式化之後的日期物件] */ // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 Date.prototype.format = function(format) { var o = { "M+" : this.getMonth() + 1, // month "d+" : this.getDate(), // day "h+" : this.getHours(), // hour "m+" : this.getMinutes(), // minute "s+" : this.getSeconds(), // second "q+" : Math.floor((this.getMonth() + 3) / 3), // quarter "S" : this.getMilliseconds()// millisecond }; if (/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); } for ( var k in o) { if (new RegExp("(" + k + ")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)); } } return format; }; /** * 對Date的擴充套件,將 Date 轉化為指定格式的String * 月(M)、日(d)、12小時(h)、24小時(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 個佔位符 * 年(y)可以用 1-4 個佔位符,毫秒(S)只能用 1 個佔位符(是 1-3 位的數字) * eg: * (new Date()).pattern("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 * (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04 * (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 週二 08:09:04 * (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04 * (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18 * var date = new Date(); * window.alert(date.pattern("yyyy-MM-dd hh:mm:ss")); */ Date.prototype.pattern=function(fmt) { var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小時 "H+" : this.getHours(), //小時 "m+" : this.getMinutes(), //分 "s+" : this.getSeconds(), //秒 "q+" : Math.floor((this.getMonth()+3)/3), //季度 "S" : this.getMilliseconds() //毫秒 }; var week = { "0" : "/u65e5", "1" : "/u4e00", "2" : "/u4e8c", "3" : "/u4e09", "4" : "/u56db", "5" : "/u4e94", "6" : "/u516d" }; if(/(y+)/.test(fmt)){ fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); } if(/(E+)/.test(fmt)){ fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[this.getDay()+""]); } for(var k in o){ if(new RegExp("("+ k +")").test(fmt)){ fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); } } return fmt; } Array.prototype.max = function() { // 最大值 return Math.max.apply({}, this); }; Array.prototype.min = function() { // 最小值 return Math.min.apply({}, this); }; Array.prototype.indexOf = function(el) { for (var i = 0, n = this.length; i < n; i++) { if (this[i] === el) { return i; } } return -1; }; /** * 刪除陣列指定下標或指定物件 */ Array.prototype.remove = function(obj) { for (var i = 0; i < this.length; i++) { var temp = this[i]; if (!isNaN(obj)) { temp = i; } if (temp == obj) { for (var j = i; j < this.length; j++) { this[j] = this[j + 1]; } this.length = this.length - 1; } } }; // 區域性作用域中使用$來引用jQuery })(jQuery); /* * ! [Cookie基本操作] * @param {[Windo]} win [description] * @param {[Document]} doc) { var exp, strsec; var getsec [description] * @return {[type]} [description] */ var EmCookie = (function(win, doc) { var exp, strsec; var getsec = function(str) { var str1 = str.substring(1, str.length) * 1; var str2 = str.substring(0, 1); if (str2 == "s") { return str1 * 1000; } else if (str2 == "h") { return str1 * 60 * 60 * 1000; } else if (str2 == "d") { return str1 * 24 * 60 * 60 * 1000; } }; /** * [get 獲取Cookie] * @param {[String]} name [Cookie名稱] * @return {[Object]} [Cookie對應的值] */ var get = function(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = doc.cookie.match(reg)) { return unescape(arr[2]); } else { return null; } }; /** * [set 設定Cookie,預設設定30天] * @param {[String]} name [Cookie名稱] * @param {[Object]} value [Cookie值] * @param {[Date]} time [過期時間,s20是代表20秒,h是指小時,如12小時則是:h12,d是天數,30天則:d30] */ var set = function(name, value, time) { exp = new Date(); if (CommonUtil.notNull(time)) { strsec = getsec(time); } else { strsec = getsec("d30"); } exp.setTime(exp.getTime() + strsec * 1); doc.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); }; /** * [remove 刪除Cookie] * @param {[String]} name [Cookie名稱] */ var remove = function(name) { exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = get(name); if (cval != null) { doc.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); } }; var clear = function() { var keys = document.cookie.match(/[^ =;]+(?=\=)/g); if (keys) { for (var i = keys.length; i--;) document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString();// + "; path=/yxw/"; } }; //document.cookie; return { get: get, set: set, remove: remove, clear: clear } }(window, document));var matched, browser; jQuery.uaMatch = function( ua ) { ua = ua.toLowerCase(); var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+)/.exec( ua ) || /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || /(msie) ([\w.]+)/.exec( ua ) || ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || []; return { browser: match[ 1 ] || "", version: match[ 2 ] || "0" }; }; matched = jQuery.uaMatch( navigator.userAgent ); browser = {}; if (matched.browser) { browser[matched.browser] = true; browser.version = matched.version; } // Chrome is Webkit, but Webkit is also Safari. if ( browser.chrome ) { browser.webkit = true; } else if ( browser.webkit ) { browser.safari = true; } jQuery.browser = browser; /* //下面是直接寫的判斷,上面jq的獲取方法 if (matched.browser == 'mozilla') { $('#Online-message .liuyan').css({'padding-left': '0px','padding-right': '0px'}) } if (!$.support.leadingWhitespace) { $("#browser_ie").show(); } */ /* * 瀏覽器全屏 */ function fullScreen() { var el = document.documentElement; var rfs = el.requestFullScreen || el.webkitRequestFullScreen; if (typeof rfs != "undefined" && rfs) { rfs.call(el); } else if (typeof window.ActiveXObject != "undefined") { var wscript = new ActiveXObject("WScript.Shell"); if (wscript != null) { wscript.SendKeys("{F11}"); } } else if (el.msRequestFullscreen) { el.msRequestFullscreen(); } else if (el.oRequestFullscreen) { el.oRequestFullscreen(); } else { swal({ title : "瀏覽器不支援全屏呼叫!", text : "請更換瀏覽器或按F11鍵切換全屏!(3秒後自動關閉)", type : "error", timer : 3000 }); } } /* * 瀏覽器退出全屏 */ function exitFullScreen() { var el = document; var cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.exitFullScreen; if (typeof cfs != "undefined" && cfs) { cfs.call(el); } else if (typeof window.ActiveXObject != "undefined") { var wscript = new ActiveXObject("WScript.Shell"); if (wscript != null) { wscript.SendKeys("{F11}"); } } else if (el.msExitFullscreen) { el.msExitFullscreen(); } else if (el.oRequestFullscreen) { el.oCancelFullScreen(); } else { swal({ title : "瀏覽器不支援全屏呼叫!", text : "請更換瀏覽器或按F11鍵切換全屏!(3秒後自動關閉)", type : "error", timer : 3000 }); } } Scaling = {}; ;(function(win, doc, $){ Scaling.zoom = function() { var ww = $(window).width(); if(!$.browser.webkit) { if(ww < 1370 && ww > 1030) { $('body').addClass("scaling1366"); } else if (ww < 1030 && ww < 965) { $('body').addClass("scaling1024"); } else if (ww < 965 && ww < 0) { $('body').addClass("scaling960"); } } } } (window, document, jQuery)); // JavaScript Document // 通告無縫滾動 ;(function($) { /** 呼叫Demo: $("#largeEarlyWarningCon").myScroll({ speed: 40, // 數值越大,速度越慢 rowHeight: 26 // li的高度 }); */ $.fn.myScroll = function(options) { var defaults = { speed: 40, rowHeight: 24 }; var opts = $.extend({}, defaults, options), intId = []; function marquee(obj, step) { obj.find("ul").animate({ marginTop: '-=1' }, 0, function() { var s = Math.abs(parseInt($(this).css("margin-top"))); if (s >= step) { $(this).find("li").slice(0, 1).appendTo($(this)); $(this).css("margin-top", 0); } }); } this.each(function(i) { var sh = opts["rowHeight"], speed = opts["speed"], _this = $(this); intId[i] = setInterval(function() { if (_this.find("ul").height() <= _this.height()) { clearInterval(intId[i]); } else { marquee(_this, sh); } }, speed); _this.hover(function() { clearInterval(intId[i]); }, function() { intId[i] = setInterval(function() { if (_this.find("ul").height() <= _this.height()) { clearInterval(intId[i]); } else { marquee(_this, sh); } }, speed); }); }); } })(jQuery);