参考文献:JQ动画
1、显示与隐藏
1、slideToggle 方法 - 检查被选元素的可见状态。
2、slow- 动画缓动值。
3、scrollTop 方法 - 返回或者设置匹配元素的滚动条的垂直位置,方法对于可见元素和不可见元素具有效。
/* 支持JQ 1.10.2.min.js*/
$(function() {
$(".downmenu").click(function() {
$(".slideMenu").slideToggle("slow");
})
$(window).scroll(function() {
/* 导航顶部 */
if ($(window).scrollTop > 120 ) {
$(".slideMenu").hide();
}
})
})
2、添加类
1、 attr 其实就是原生js中 getAttribute 的简化实现,设置或返回被选元素的属性和值,而removeAttr 就是 removeAttribute 的简写;
2、find() 方法返回被选元素的后代元素,即返回 paylist-item 后代中所有的 icon-select 元素;
$(".paylist-item").click(function () {
//siblings是循环遍历
$(".paylist-item").siblings().find(".icon-select").attr('class', 'icon-select');
$(this).find(".icon-select").attr('class', "icon-select item-selecteds");
})
3、添加、移除类
$(document).ready(function(){
var liTags = $('.div').find('li');
//$.each() 遍历处理二维数组
$.each(liTags,function(i,li) {
let cid = i
var _this = $(this)
_this.on('mouseover',function() {
var tops = $('.divs').find('.pp');
$.each(tops,function(i,top) {
var _this = $(this)
_this.removeClass('actives')
})
$.each(liTags,function(i,li) {
var _this = $(this)
_this.removeClass('active')
})
_this.addClass('active')
$('[cid='+cid+']').addClass('actives')
})
})
})