標籤:style blog io color ar sp strong 資料 div
1.each() 方法規定為每個匹配元素規定啟動並執行函數。
$.each(data,function(index,item){ sb.append(item.answerNum); }$(".switchBox").each(function() { var id = $(this).attr("id"); var type = $(this).attr("typeId"); createSlideDiv(id, type, fn); });//attr() 方法設定或返回被選元素的屬性值。
2.方法回調
if ($.isFunction(loadData)) loadData(obj);$(function(){ //初始化滑動div loadSwitchBox(‘.boxwrap‘,loadData,‘#sub-frameMain‘,‘tab_1.html‘); }); //載入頁面資料 function loadData(){ }
3 :eq() 選取器選取帶有指定 index 值的元素。
var default_BtnWidth = $wraper.find(‘.swichTxt‘).eq(0).width()
oldIndex = $wraper.find(‘.cur‘).index(),
4. animate() 方法執行 CSS 屬性集的自訂動畫。
該方法通過CSS樣式將元素從一個狀態改變為另一個狀態。CSS屬性值是逐漸改變的,這樣就可以建立動畫效果。
$wraper.find(".switchBtn").animate({ ‘left‘: ‘+=‘ + distant + ‘px‘ }, function() { $wraper.find(‘.curTxt‘).html(curTxt); $wraper.find("#switchBtn").width(eleWidth); //執行回呼函數 if ($.isFunction(fnCallBack)) fnCallBack(obj); });//設定switchBtn的左位移,
5.outerWidth(options)
擷取第一個匹配元素外部寬度(預設包括補白和邊框)。
此方法對可見和隱藏元素均有效。
傳回值:Integer
wrapperWidth += $(this).outerWidth() + oPadding;
6.offset() 方法返回或設定匹配元素相對於文檔的位移(位置)。
//當前span左側位置離左邊的距離
var curBtn = $s_btn.offset().left;
js常用函數陸續總結