2012-08-03 29 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