最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery 設(shè)置元素相對(duì)于另一個(gè)元素的top值(實(shí)例代碼)

 更新時(shí)間:2013年11月06日 08:43:50   投稿:jingxian  
在jquery中offset().top是相對(duì)于body來(lái)說(shuō)的,另外在設(shè)置top值的時(shí)候要找到與該元素最近的有相對(duì)值的元素

<div id="span1">sfdsfsddfsdf</div>
<span id="span2" style="position:relative">

        <input id="input" type="text"></input>
        <input id="button" type="button"></input>

 </span>

設(shè)置button在input的下方

$("#button").css("{top":$("#input").offset().top-$("#span2").offset().top+$("#input").height,position:"absolute"});

這樣input在哪個(gè)位置button都在input的下邊,同樣可以運(yùn)用到日歷小插件在input文本框的下方

1、在jquery中offset().top是相對(duì)于body來(lái)說(shuō)的,另外在設(shè)置top值的時(shí)候要找到與該元素最近的有相對(duì)值的元素

在js中可以這樣寫(xiě):

復(fù)制代碼 代碼如下:

//取得HTML控件絕對(duì)位置
Calendar.prototype.getAbsPoint = function (e){
  var x = e.offsetLeft;
  var y = e.offsetTop;
  while(e = e.offsetParent){
    x += e.offsetLeft;
    y += e.offsetTop;
  }
  return {"x": x, "y": y};
}

 var xy = this.getAbsPoint(popControl);
   this.panel.style.left = xy.x  + "px";

  this.panel.style.top = (xy.y + dateObj.offsetHeight) + "px";


如圖所示:

相關(guān)文章

最新評(píng)論

驻马店市| 雷州市| 黑水县| 遵义县| 海兴县| 沂源县| 武川县| 商都县| 区。| 葫芦岛市| 隆林| 桓台县| 张家港市| 和政县| 凤翔县| 错那县| 江山市| 江津市| 随州市| 霍城县| 资阳市| 两当县| 普宁市| 曲靖市| 沂南县| 富民县| 高雄市| 莲花县| 喜德县| 香河县| 新昌县| 墨江| 小金县| 深水埗区| 本溪市| 东莞市| 龙川县| 韶关市| 南康市| 青岛市| 顺昌县|