2010-11-01 117 views
1

请参阅本UI sketch的形象,我在某个网站上的侧边栏(黑匣子)这个div和我向下滚动或滚动起来,我不希望它隐藏......当我向下滚动并向上移动时,我希望它自动向下移动,因为我向后滚动以便它永远不会隐藏。你能推荐我一些可以完成这个工作的jQuery吗?或者是其他东西。请帮忙,谢谢。自动定位格为一个滚动页面向下/向上

回答

9

不要使用jQuery为此请;它是纯粹的CSS。

#MyDiv 
{ 
    position: fixed; 
    top: 10px; 
    left: 10px; 
} 

通过调整topleft调整到您喜欢的确切位置。也许你希望它在图像垂直居中一样(如果草图是准确的在这方面),在这种情况下,你必须处理所有的乐趣tricks necessary for vertical centering;希望在你的情况下这样的事情可以工作:

#MyDiv 
{ 
    position: fixed; 
    top: 50%; /* This places the _top_ of the div in the middle of the page. */ 
    left: 10px; 
    height: 500px; 
    margin-top: -250px; /* This moves the div upward by half of its height, 
          thus aligning the middle of the div with the middle 
          of the page. */ 
} 
+0

是的。 jQuery!=即时解决方案。 – 2010-11-01 20:48:43

+0

其实我不想在div在页面中间正好进行调整,仅在页面加载时。我希望随着用户向下滚动以显示更多内容而实时调整该div,div也保持向下滚动以保持对用户可见。我希望你现在 – 2010-11-01 20:50:55

+0

是的,这就是为什么我们使用'位置:中fixed'代替'位置:absolute'。 – Domenic 2010-11-01 20:51:52