API
事件(Events)
// 页面完全加载后执行(包括图形)
$(window).load(() => {
})
// DOM 结构完全渲染之后执行
$(document).ready(() => {
});
$( "li.fade" ).hover(function() {
$( this ).fadeOut( 100 );
$( this ).fadeIn( 500 );
});
过滤器(Filtering)
- eq(): 通过下标匹配元素。
树形遍历(Tree)
- find(): 查找子元素。
元素(DOM )
// 安全清空(推荐)
$('#element').empty();
// 等效原生方法
document.getElementById('element').innerHTML = '';
index()
如果我们省略参数,.index()
将返回匹配元素集中第一个元素相对于其兄弟姐妹的位置:
alert( "Index: " + $( "#bar" ).index() );
查看被点击项目的下标:
$(this.el).on("click", ".animation-item", (e) =>{
const index = $('.animation-item').index(e.currentTarget);
//...
})
样式属性(style)
- width()
- css(): 修改csss属性。
- addClass()
属性
- attr(): 获取元素属性