1

我正在处理其他人整理的一些代码。这个想法是在一个页面上你有多个表格。首先,它们只是一个图像,但是当您单击图像时,您可以查看整个表格。这些表格被包裹在一个 div 覆盖层中,该覆盖层根据您在页面上的位置控制表格的位置。

该脚本基本上会找到您在页面上的位置,然后将“顶部”属性添加为内联样式,像素将取决于您单击的表格以及您在页面上的位置。它在除 IE7 / 8 之外的所有浏览器中都能正常工作。

我已经解决了问题,它没有将“顶部”属性添加为内联样式。在 IE7 / 8 中。我尝试添加一个可以在其中添加顶部的类,但不能以这种方式动态添加样式。

无论如何,这里有一些代码:

添加 top 属性的 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' 属性。

我知道缺少代码,但我希望你不再需要,因为我(手指交叉)发现了问题。

谢谢!

乔什

答案*

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;
    }
    }
4

2 回答 2

0

尝试将 position:relative 放在其父级上。

于 2012-09-17T23:56:28.350 回答
0

函数 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;
    }
    }
于 2012-09-28T16:08:23.440 回答