Jump to content

ScrollBar


_bernardo_
 Share

Recommended Posts

em css, tenho tido alguns problemas para que funcione correctamente em todos os browsers... em js, tenho isto:

<style type="text/css">

.dockclass{
position:relative;
}

</style>

<body>

<script type="text/javascript">

/***********************************************
* Dock Content script- Created by and © Dynamicdrive.com
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full script
***********************************************/

var offsetfromedge=0      //offset from window edge when content is "docked". Change if desired.
var dockarray=new Array() //array to cache dockit instances
var dkclear=new Array()   //array to cache corresponding clearinterval pointers

function dockit(el, duration){
this.source=document.all? document.all[el] : document.getElementById(el);
this.source.height=this.source.offsetHeight;
this.docheight=truebody().clientHeight;
this.duration=duration;
this.pagetop=0;
this.elementoffset=this.getOffsetY();
dockarray[dockarray.length]=this;
var pointer=eval(dockarray.length-1);
var dynexpress='dkclear['+pointer+']=setInterval("dockornot(dockarray['+pointer+'])",100);';
dynexpress=(this.duration>0)? dynexpress+'setTimeout("clearInterval(dkclear['+pointer+']); dockarray['+pointer+'].source.style.top=0", duration*1000)' : dynexpress;
eval(dynexpress);
}

dockit.prototype.getOffsetY=function(){
var totaloffset=parseInt(this.source.offsetTop);
var parentEl=this.source.offsetParent;
while (parentEl!=null){
totaloffset+=parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function dockornot(obj){
obj.pagetop=truebody().scrollTop;
if (obj.pagetop>obj.elementoffset) //detect upper offset
obj.source.style.top=obj.pagetop-obj.elementoffset+offsetfromedge+"px";
else if (obj.pagetop+obj.docheight<obj.elementoffset+parseInt(obj.source.height)) //lower offset
obj.source.style.top=obj.pagetop+obj.docheight-obj.source.height-obj.elementoffset-offsetfromedge+"px";
else
obj.source.style.top=0;
}

function truebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

</script>

o que tens a fazer é colocar o conteúdo que queres dentro de uma div:

<div id="dockcontent0" class="dockclass">This DIV content is docked</div>
Docked image: <img src="test.gif" id="dockcontent1" class="dockclass" />

mesmo antes do </body>, colocas:

<script type="text/javascript">
var dock0=new dockit("dockcontent0", 0);
var dock1=new dockit("dockcontent1", 0);
</script>

em que o dockcontent0 é o nome da class que deste anteriormente à div e o numero a seguir é o tempo que a div se mantém fixa: 0 para permanente ou outro valor em segundos...

dock0 (ou outro nome qualquer) tem de ser um nome unico e tens de criar um para cada div fixo que queiras...

há 10 tipos de pessoas: as que sabem binário e as que não sabem... todas as nossas vidas não passam de release candidates... com o aperfeiçoamento, um dia chegaremos à versão final..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.