2019-06-17 jQuery循环 元素绝对位置

1.jQuery循环

$(function(){

// //给全部的li设置内容和样式

// $('.list li').html('111');

// $('.list li').css({background:'gold'});

//第一个参数index是索引值

$('.list li').each(function(index) {

// alert(index);//弹出索引值

//$(this)是每一个li

$(this).html(index);

});

})

2.元素绝对位置

$(function(){

var $pos = $('.pos');

//offset()是获取相对于页面左上角的绝对位置,即使外面再包一层con居中层,也不影响效果

var pos = $pos.offset();

// console.log(pos);

// alert(pos.left + "," + pos.top);

var w = $pos.outerWidth();

var h = $pos.outerHeight();

// alert(w);

$('.pop').css({left:pos.left + w,top:pos.top});

$pos.mouseover(function() {

$('.pop').show();

});

$pos.mouseout(function() {

$('.pop').hide();

});

})

你可能感兴趣的:(2019-06-17 jQuery循环 元素绝对位置)