始终使用jQuery确保div标签位于页面顶部
问题描述:
我有一个div标签<div id="customError">Error</div>
我希望使用jQuery这个div标签始终显示在页面顶部,因此,即使页面是可滚动的,也要使用其他单词,我希望它始终可见并位于页面顶部就像*通知栏一样.使用JQuery是否可能?我尝试了许多操作,当页面向下滚动时,它消失了.任何帮助建议将不胜感激.
I have a div tag <div id="customError">Error</div>
I want this div tag to always appear at the top of the page using jquery, so with otherwords even if the page is scrollable I want it to be always visible and on top of the page almost like the * notification bar. Is this possible using JQuery? I tried a number of things and it disappears when the page is scrolled down. Any help advise will be appreciated.
答
您只能使用css:
#customError {
position: fixed;
top: 0;
left: 0;
width: 100%;
/* IE6 */
_position: absolute;
_top: expression(document.getElementsByTagName("body")[0].scrollTop + "px");
}