2012-08-03 87 views
-2

我正尝试重新创建一个非常类似于Beyonce's Tumblr page上看到的菜单。我用什么html/css标签来创建该效果?我指的是点击箭头时滑过的菜单。如何使用HTML或CSS代码创建滚动菜单?

+1

有很多的方式来实现这样的影响。如果你想模仿特定的效果,为什么不看源头? – 2012-08-03 07:59:50

+2

很难不在你身上挖掘你的努力,但我会尽力。为了在stackoverflow上获得帮助,你应该首先尝试让它发生,如果你无法完成它的工作,请回到这里,展示你的代码并寻求社区的帮助。 – 2012-08-03 08:01:31

+0

我已经看过源代码并试图复制它,但是当我将它放入我的网站时,它并没有保持相同的功能和事实,摆脱了背后的内容......所以我尝试了要做到这一点,只是没有把代码放在里面。我是新来的。 – atl 2012-08-03 20:10:17

回答

1

想要读取this article用于在CSS3/HTML中创建基本菜单,在网站中,您可以生成一个带有HTML/CSS的菜单... BUt为了获得更多效果,可以使用Javascript库[示例:JqueryUI demo effects]。 ..

1

这是一个非常基本的例子,让你开始。

HTML

​<div id="menu"> 
    Hello world! 
    <div class="tab">&gt;</div> 
</div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ 

CSS

​#menu { 
    width: 600px; 
    height: 300px; 
    background: #000; 
    position: absolute; 
    left: -600px; 
    top: 50px; 
    color: #FFF; 
} 

.tab { 
    width: 40px; 
    height: 40px; 
    background: red; 
    position: absolute; 
    right: -40px; 
    top: 0; 
    color: #FFF: 
} 

JQuery的

$(document).ready(function() { 
    $(".tab").toggle(function() { 
     $('#menu').animate({ left: '0' }, 500); 
    }, function() { 
     $('#menu').animate({ left: '-600' }, 500); 
    });​ 
}); 

WORKING EXAMPLE

+0

我试图插入这个,但仍然没有在我的博客上工作。也许我把它放在了错误的地方? – atl 2012-08-03 20:55:35

+0

这个网站还是新手,不确定在这里复制和粘贴源代码的位置,但是你可以在http://actuallyandy.tumblr.com/ – atl 2012-08-03 20:56:38

1

这是一个实现。你需要插入以下不同的部分:

头部分:

<style> 
<!-- 
#slidemenubar, #slidemenubar2{ 
position:absolute; 
border:1.5px solid black; 
background-color:#F2F2F2; 
layer-background-color:#F2F2F2; 
font:bold 12px Verdana; 
line-height:20px; 
} 
--> 
</style> 

主体部分

<script language="JavaScript1.2"> 

var slidemenu_width='160px' //specify width of menu (in pixels) 
var slidemenu_reveal='12px' //specify amount that menu should protrude initially 
var slidemenu_top='170px' //specify vertical offset of menu on page 

var ns4=document.layers?1:0 
var ie4=document.all 
var ns6=document.getElementById&&!document.all?1:0 

if (ie4||ns6) 
document.write('<div id="slidemenubar2" style="left:'+((parseInt(slidemenu_width)- parseInt(slidemenu_reveal))*-1)+'px; top:'+slidemenu_top+'; width:'+slidemenu_width+'"  onMouseover="pull()" onMouseout="draw()">') 
else if (ns4){ 
document.write('<style>\n#slidemenubar{\nwidth:'+slidemenu_width+';}\n<\/style>\n') 
document.write('<layer id="slidemenubar" left=0 top='+slidemenu_top+'  width='+slidemenu_width+' onMouseover="pull()" onMouseout="draw()" visibility=hide>') 
} 

var sitems=new Array() 

///////////Edit below///////////////////////////////// 

//siteitems[x]=["Item Text", "Optional URL associated with text"] 

sitems[0]=["<big><font face='Arial'>Site Menu</font></big>", ""] 
sitems[1]=["Link 1", "http://www.google.com/"] 
sitems[2]=["Link 2", "http://www.link2.com/"] 
sitems[3]=["Link 3", "http://www.link3.com/"] 
sitems[4]=["Link 4", "http://www.link4.com/"] 
sitems[5]=["Link 5", "http://www.link5.com/"] 
sitems[6]=["Link 6", "http://www.link6.com/"] 
sitems[7]=["Link 7", "http://www.link7.com/"] 

//If you want the links to load in another frame/window, specify name of target (ie:  target="_new") 
var target="" 

///////////////////////////////////////////////////////// 

if (ie4||ns4||ns6){ 
for (i=0;i<sitems.length;i++){ 
if (sitems[i][1]) 
document.write('<a href="'+sitems[i][1]+'" target="'+target+'">') 
document.write(sitems[i][0]) 
if (sitems[i][1]) 
document.write('</a>') 
document.write('<br>\n') 
} 
} 

function regenerate(){ 
window.location.reload() 
} 
function regenerate2(){ 
if (ns4){ 
document.slidemenubar.left=((parseInt(slidemenu_width)-parseInt(slidemenu_reveal))*-1) 
document.slidemenubar.visibility="show" 
setTimeout("window.onresize=regenerate",400) 
} 
} 
window.onload=regenerate2 

rightboundary=0 
leftboundary=(parseInt(slidemenu_width)-parseInt(slidemenu_reveal))*-1 

if (ie4||ns6){ 
document.write('</div>') 
themenu=(ns6)? document.getElementById("slidemenubar2").style :  document.all.slidemenubar2.style 
} 
else if (ns4){ 
document.write('</layer>') 
themenu=document.layers.slidemenubar 
} 

function pull(){ 
if (window.drawit) 
clearInterval(drawit) 
pullit=setInterval("pullengine()",10) 
} 
function draw(){ 
clearInterval(pullit) 
drawit=setInterval("drawengine()",10) 
} 
function pullengine(){ 
if ((ie4||ns6)&&parseInt(themenu.left)<rightboundary) 
themenu.left=parseInt(themenu.left)+10+"px" 
else if(ns4&&themenu.left<rightboundary) 
themenu.left+=10 
else if (window.pullit){ 
themenu.left=0 
clearInterval(pullit) 
} 
} 

function drawengine(){ 
if ((ie4||ns6)&&parseInt(themenu.left)>leftboundary) 
themenu.left=parseInt(themenu.left)-10+"px" 
else if(ns4&&themenu.left>leftboundary) 
themenu.left-=10 
else if (window.drawit){ 
themenu.left=leftboundary 
clearInterval(drawit) 
} 
} 
</script> 
+0

查看代码。好吧@CamelUno,所以我使用了这段代码但是,当我对值进行调整以使菜单变大时,菜单完全从我的页面中消失。我在之后立刻将头部伸出,然后在右侧之后的身体部分 – atl 2012-08-04 08:56:17

+0

我试图将整个源代码展示给您,但它不会让我 – atl 2012-08-04 09:04:57