曾经我们对于jquery实现的lavalamp那是极度热爱啊,现在不用借助jquery,我们用纯css3实现了,过瘾啊。技术的关键在于在菜单的li最后先增加一个空元素来承载那个滑动的东西,再使用css3的兄弟元素选择器~,然后对于不同的li滑过的时候,设置承载滑动的那个元素的left位置。
css主要代码:
#lavalamp { background: url('lavalamp.png') no-repeat scroll 0 0 transparent; height: 16px; left: 13px; position: absolute; top: 0px; width: 64px; -moz-transition: all 300ms ease; -ms-transition: all 300ms ease; -o-transition: all 300ms ease; -webkit-transition: all 300ms ease; transition: all 300ms ease; } #lavalamp:hover { -moz-transition-duration: 3000s; -ms-transition-duration: 3000s; -o-transition-duration: 3000s; -webkit-transition-duration: 3000s; transition-duration: 3000s; } #nav li:nth-child(1):hover ~ #lavalamp { left: 13px; } #nav li:nth-child(2):hover ~ #lavalamp { left: 90px; } #nav li:nth-child(3):hover ~ #lavalamp { left: 170px; } #nav li:nth-child(4):hover ~ #lavalamp { left: 250px; } #nav li:nth-child(5):hover ~ #lavalamp { left: 330px; } #nav li:nth-child(6):hover ~ #lavalamp { left: 410px; } #nav li:nth-child(7):hover ~ #lavalamp { left: 490px; } #nav li:nth-child(8):hover ~ #lavalamp { left: 565px; }
更多资料:http://www.script-tutorials.com/pure-css3-lavalamp-menu/