2013-04-17 97 views
2

我用window.pageYOffset找到滚动条的位置(在Firefox正常工作),但它是在IE10Internet Explorer的10和top.window.pageYOffset

总是不确定我已经尝试使用:

window.pageYOffset // undefined 
document.body.scrollTop // always 0 
document.documentElement.scrolltop // undefined 
top.window.scrollY // undefined 

这是IE10的一个已知问题?

这是启用兼容模式。没有它,pageYOffset按预期工作。我们必须使用兼容模式,因为这是我们客户的要求

代码显示一个calander,它需要在文本框中显示。当用户在页面上滚动它的位置将发生改变:用代码已更新 :

function showCalendar(e, datePicker) { 
    top.calendarReturnFunc = function(value, controlId) { 
     getDatePicker(controlId).dateBox.hasDate = "True"; 
     dateChosen(value, controlId, true); 
    }; 
    top.datePickerActive = function() { return true; }; 
    var itop = top.window.screenTop != undefined ? top.window.screenTop : parseInt(top.window.screenY) + parseInt(130); 
    var ileft = top.window.screenLeft != undefined ? top.window.screenLeft : parseInt(top.window.screenX); 


    var x = e.screenX - parseInt(ileft); 
    var y; 

    if (typeof top.window.pageYOffset === "undefined") { 
     y = (e.screenY - parseInt(itop) - datePicker.yOffset) + document.documentElement.scrollTop; //IE10?... 
    } 
    else { 
     y = (e.screenY - parseInt(itop) - datePicker.yOffset) + top.window.pageYOffset; //works fine in firefox 
    } 

    if (datePicker.alignLeft) { 
     x -= 180; 
    } 
    if (!datePicker.alignBottom) { 
     y -= 178; 
    } 
    _calendar.style.left = x + "px"; 
    _calendar.style.top = y + "px"; 
    _calendar.style.display = "block"; 
    _calendar.datePicker = datePicker; 
    _calendar.callingFrame = this; 
    _calendar.src = datePicker.calendarUrl + "&Date=" + escape(datePicker.dateBox.value); 
} 
+0

你试过'window.top.scrollY'吗? – andlrc

+0

叶刚试过,仍然没有定义。感谢您的回复:) – Alex

+1

'window.pageYOffset'适用于IE10。 – Christoph

回答

2

可以使用document.documentElement.scrollTop的IE浏览器。您的示例中没有将scrollTop中的T大写。

+0

我会给这个尝试 – Alex

+1

啊,我已经拥有它,仍然没有工作 – Alex

+0

你能提供一个链接到您的网页或jsfiddle演示?它应该正常工作,所以也许别的东西正在阻碍。您可以通过在任何页面上打开F12开发工具并在控制台中运行它来确认它。 –