PDA

View Full Version : How to create a menu that appears after scrolling?



madnhate
06-08-2012, 09:09 PM
How to create a menu that appears after scrolling? As in it doesn't appear until you scroll a bit away from the top. How would I acheive the effects that are used to make them appear?


Examples of what I'm talking about: (scroll down a bit)
Example 1 (http://www.tripadvisor.co.uk/Hotel_Review-g187791-d191099-Reviews-Albergo_del_Senato-Rome_Lazio.html)

Example 2 (http://www.albergodelsenato.it/)

ajfmrf
06-09-2012, 12:18 AM
those are not menus they are forms to use for each of the sites

vwphillips
06-09-2012, 09:21 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/
BODY {
height:3000px;
}

#tst {
position:fixed;z-Index:101;left:0px;top:0px;height:100px;width:100%;background-Color:red;
}

/*]]>*/
</style>

</head>

<body>
<div id="tst" >content goes here</div>

<script type="text/javascript">
/*<![CDATA[*/

var zxcFadePanel={

init:function(o){
var ms=o.FadeDuration,show=o.ShowAt,obj={
obj:document.getElementById(o.ID),
show:typeof(show)=='number'?show:0,
ms:typeof(ms)=='number'?ms:10,
now:0,
to:100
}
this.addevt(window,'scroll','scroll',obj);
this.scroll(obj);
},

scroll:function(o){
var top=document.body.scrollTop,to;
if (window.innerHeight){
top=window.pageYOffset;
}
else if (document.documentElement.clientHeight){
top=document.documentElement.scrollTop;
}
to=top<o.show?0:100;
if (to!=o.to){
o.to=to;
clearTimeout(o.dly);
o.obj.style.visibility='visible';
this.animate(o,o.now,to,new Date(),o.ms*Math.abs((to-o.now)/100));
}
},

animate:function(o,f,t,srt,mS){
var oop=this,ms=new Date().getTime()-srt,now=(t-f)/mS*ms+f;
if (isFinite(now)){
o.now=now;
o.obj.style.filter='alpha(opacity='+now+')';
o.obj.style.opacity=o.obj.style.MozOpacity=o.obj.style.WebkitOpacity=o.obj.style.KhtmlOpacity=now/100-.001;
}
if (ms<mS){
o['dly']=setTimeout(function(){ oop.animate(o,f,t,srt,mS); },10);
}
else {
o.now=t;
o.obj.style.visibility=t==100?'visible':'hidden';
}
},

addevt:function(o,t,f,p){
var oop=this;
if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](p);}, false);
else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](p); });
}

}

zxcFadePanel.init({
ID:'tst',
ShowAt:500,
FadeDuration:1000
});

/*]]>*/
</script>
</body>

</html>

coothead
06-09-2012, 10:27 AM
Hi there madnhate,

I was working on this also and did not see our friend Vic's post. :o

As I have an example, I might as well post it...


<!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8">


<title></title>

<style>
body {
margin:0;
background-color:#f0f0f0;
font-family:verdana,arial,helvetica,sans-serif;
font-size:100%;
}
#header {
position:fixed;
top:0;
height:100px;
padding:10px;
border-bottom:1px solid #c60;
background-color:#fb7;
box-shadow:0 4px 12px #333;
opacity:0;
filter:alpha(opacity=0);
color:#c60;
}
#header p{
margin:0;
clear:both;
}
.hide {
display:none;
}
#close {
float:right;
width:18px;
line-height:18px;
border:1px solid #c60;
text-align:center;
font-size:75%;
cursor:pointer;
background-color:#fc9;
box-shadow:2px 2px 3px #666;
}
#container {
width:960px;
height:1500px; /* this is here to force vertical scrolling and should be removed when unnecessary */
padding:20px;
margin:auto;
}
</style>

<script>

function init() {

test=true;
c=0;
obj=document.getElementById('header')
onscroll=function(){

/*@cc_on!@*/false?x=document.body.parentNode.scrollTop:x=pageYOffset;

if((x>140)&&(test==true)) {
test=false;
c=0;
obj.className='';
showHeader();
}
if((x<140)&&(test==false)) {
test=true;
c=100;
showHeader();
}
}
document.getElementById('close').onclick=function() {
obj.className='hide';
}
}
function showHeader() {
test==true?c--:c++;
if((c>100)||(c<0)){
return;
}
if(obj.filters){
obj.style.filter='alpha(opacity='+c+')';
}
else {
obj.style.opacity=c/100;
}
setTimeout(function(){showHeader();},10);
}

window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
</script>

</head>
<body>

<div id="header">
<span id="close">x</span>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
ultricies sollicitudin nisi, ut molestie felis adipiscing sit
amet. Sed auctor vehicula commodo. Nam a nibh neque, vitae
faucibus felis. Vivamus at metus eget eros consequat fringilla.
Quisque magna magna, laoreet eu tempus sit amet, fringilla at
tellus. Praesent felis tortor, scelerisque vitae fringilla
non, porttitor et lacus. Ut ut sapien nec quam tincidunt
consectetur in nec lacus.
</p>
</div>
<div id="container">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec
ultricies sollicitudin nisi, ut molestie felis adipiscing sit
amet. Sed auctor vehicula commodo. Nam a nibh neque, vitae
faucibus felis. Vivamus at metus eget eros consequat fringilla.
Quisque magna magna, laoreet eu tempus sit amet, fringilla at
tellus. Praesent felis tortor, scelerisque vitae fringilla
non, porttitor et lacus. Ut ut sapien nec quam tincidunt
consectetur in nec lacus.
</p><p>
Phasellus porta, dui a elementum egestas, odio sapien rhoncus
lorem, vitae bibendum erat sem eget sapien. Maecenas ut metus
ac quam pellentesque lacinia quis sit amet augue. Fusce eu
euismod urna. Nunc volutpat scelerisque tempus. Donec eget arcu
et mauris scelerisque tristique. Donec fringilla mauris dolor,
sit amet vulputate lacus. Nulla feugiat mattis nulla non
tincidunt. Nam sit amet dolor eros, a viverra lacus. Nunc quis
nisi eget neque tempus facilisis eu quis sapien.
</p><p>
Ut et metus a massa rhoncus cursus. Integer luctus luctus enim,
tristique rhoncus enim feugiat eu. Etiam porttitor volutpat
massa sed congue. Sed eros nisl, volutpat ac dapibus quis,
ultricies id diam. Mauris at elit eget quam ullamcorper sagittis
ac vel lorem. Ut nec justo libero. Phasellus eget pharetra elit.
Proin viverra, neque non eleifend vehicula, nulla augue gravida
felis, non fermentum lorem odio ac nunc. Aliquam pretium
scelerisque consectetur. Proin ultrices urna non magna interdum
a sodales turpis suscipit. Mauris sollicitudin nisl ac arcu
sodales cursus. Maecenas bibendum neque vitae orci mollis ac
vulputate ante auctor. Sed sodales odio id ante sagittis
faucibus.
</p><p>
Curabitur gravida, neque id volutpat tincidunt, justo eros
interdum dui, nec mattis eros nunc a ipsum. Aenean in orci id
turpis luctus interdum nec ut est. Nunc lacinia sagittis nibh
vitae bibendum. Cras malesuada, felis vitae egestas aliquet,
mauris diam vehicula quam, eget scelerisque felis nulla id
tellus. Curabitur non laoreet dolor. Vestibulum sodales
hendrerit elit vitae eleifend. Praesent faucibus mauris sed erat
accumsan ac cursus lacus molestie. Donec a nisi a risus malesuada
molestie nec at odio. Maecenas eleifend tincidunt lacus nec
vulputate. Vestibulum eleifend pulvinar sem, sit amet auctor eros
pellentesque quis. Sed et nulla non eros auctor malesuada.
Vestibulum erat arcu, hendrerit vel cursus nec, sagittis vitae
sapien. Nulla facilisi. Sed nec molestie mauris. Donec non dui
urna.
</p><p>
Aenean vel velit vel metus congue ultrices non ut lorem. Sed
viverra quam sit amet libero vestibulum eget porta sem mattis.
Pellentesque tincidunt convallis justo eu iaculis. Suspendisse
ut dui ante, et malesuada nisi. Praesent aliquet congue nulla
volutpat posuere. Curabitur orci magna, egestas nec mollis nec,
dapibus in erat. Vestibulum cursus est mauris, non gravida elit.
Curabitur at diam nisi.
</p>
</div>
</body>
</html>



The code has been tested in IE8, IE9, Firefox 13, Opera 11.64 and Safari 5.1.7. ;)

coothead