jQuery CSS 操作

今天在一个页面需要知道jquery版本号,来决定使用什么样的方法,有以下方式可以获取到

  $.fn.jquery

  $.prototype.jquery

  这两种方式都可以获取到jquery的版本号

------------------------------------------------

1.返回偏移坐标

语法

$(selector).offset()

offset() 方法返回或设置匹配元素相对于文档的偏移(位置)。

2.设置偏移坐标

语法

$(selector).offset(value)

必需。规定以像素计的 top 和 left 坐标。

可能的值:

  • 值对,比如 {top:100,left:0}
  • 带有 top 和 left 属性的对象

3. 使用函数来设置偏移坐标

语法

$(selector).offset(function(index,oldoffset))

规定返回被选元素新偏移坐标的函数。

  • index - 可选。接受选择器的 index 位置
  • oldvalue - 可选。接受选择器的当前坐标。
//old.top = 101; //有这行的话,效果很诡异!!!(不要在这个函数里面去改边old原来的值!!
有这行的话,效果很诡异!!!
$('input').eq(1).offset(function(index, old){
    console.log(++index, old)
    var newObj = new Object();
    //old.top = 101; //有这行的话,效果很诡异!!!
    console.log(old);
    newObj.top=100;
    newObj.left = old.left;
    return newObj;
})

  

原文地址:https://www.cnblogs.com/oxspirt/p/10765050.html