我正在編寫其他人放在一起的代碼。這個想法是,在一個頁面上,你在頁面上有多個表格。首先,他們只是一個圖像,但當你點擊圖像,你可以查看整個表格。這些表格包裹在一個div覆蓋層中,根據您在頁面上的位置來控制表格的位置。IE7/8動態添加css屬性'top'作爲內聯樣式
該腳本基本上可以找到您在頁面上的位置,然後將「頂部」屬性添加爲內聯樣式,並且像素將取決於您點擊哪張表以及頁面上的位置。它在所有的瀏覽器,但IE7/8工作正常。
我已經解決了問題是,它沒有添加'頂部'屬性作爲內聯樣式。在IE7/8中。我嘗試添加一個類,其中可以添加頂部,但不能以這種方式添加動態樣式。
反正這裏是一些代碼:
的JS的片段,增加了頂部屬性:
// Get the current browser size and scroll position
viewport_width = viewport().width;
viewport_height = viewport().height;
viewport_offsetx = window.pageXOffset;
viewport_offsety = window.pageYOffset;
$("#tablesorter_overlay").css("top", viewport_offsety);
table_instance = $("#tablesorter_" + $(this).attr("rel"));
table_instance.css("position", "absolute");
// Make a copy of this table so we'll have the original safe, and set it to be sorted. Add it to the overlay
new_table_instance = table_instance.clone().tablesorter();
new_table_instance.appendTo("#tablesorter_overlay");
new_table_instance.show();
//表&覆蓋HTML表已被點擊後...
<div id="tablesorter_overlay" style="top: 2803px;" class="topclass">
<p class="tablesorter_overlay_close"><a href="#">X</a></p><table cellspacing="0" cellpadding="0" class="tablesorter generic" id="tablesorter_2" style="max-width: 95%; position: absolute;">
<thead>
<tr> etc..
**注意:html代碼是firefox代碼,它在IE中是一樣的,但沒有'top'屬性。
我知道這裏缺少代碼,但我希望你不再需要(因爲手指交叉)發現問題。
謝謝!
喬希
ANSWER *
function getScrollTop(){
if(typeof pageYOffset!= 'undefined'){
//most browsers
return pageYOffset;
}
else{
var B= document.body; //IE 'quirks'
var D= document.documentElement; //IE with doctype
D= (D.clientHeight)? D: B;
return D.scrollTop;
}
}
喬希,歡迎SO。看來你已經找到了自己解決問題的辦法。在這種情況下,SO鼓勵您將解決方案作爲答案進行發佈並接受,以便因遇到同樣問題而終止在此頁面的人員可以獲得解決方案。 – vzwick 2012-09-18 00:00:34