With the answers I got from Mathias and followed by Tobias Mesquita, before its new edition.
I arrived at two similar alternative, I believe it is Cross-Browser.
1.ª.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style type="text/css">
body {
height: 999px;
}
#Pai {
position: relative;
width: 200px;
height: 200px;
border: 3px solid blue;
text-align: center;
overflow: auto;
}
#Filho {
width: 100px;
height: 100px;
margin-left: -50px;
/* metade da largura */
margin-top: -50px;
/* metade da altura */
position: absolute;
top: 50% ;
left: 50% ;
background: tomato;
z-index: 1;
opacity: .80;
}
</style>
</head>
<body>
<center>
<div id='Pai' onscroll = "rolamento()">
<p>Elemento A</p>
<p>Elemento B</p>
<p>Elemento C</p>
<p>Elemento D</p>
<p>Elemento E</p>
<p>Elemento F</p>
<p>Elemento G</p>
<p>Elemento H</p>
<p>Elemento I</p>
<p>Elemento J</p>
<div id='Filho'></div>
</div>
</center>
<script type="text/javascript">
var A = document.getElementById('Pai');
var B = document.getElementById('Filho');
var rolamento = function() {
var centralizado = A.scrollTop + 100;
B.style.top = centralizado;
}
A.onscroll = rolamento;
</script>
</body>
</html>
Follows Explanation
var A = document.getElementById('Pai'); // Div(primária)
var B = document.getElementById('Filho'); // Div(secundária)
var rolamento = function() {
var centralizado = A.scrollTop + 100; // Aqui definimos o valor 100 para reposicionar a Div(secundária) conforme o valor scrollTop() da Div(primária)
B.style.top = centralizado; // Agora vamos automatizar a Div(secundária), para retomar sempre a mesma posição inicial
}
A.onscroll = rolamento; // Escuta o evento da barra de rolagem lateral e dispara a função
NOTE - "This 1st Amendment worked perfectly on the local computer, but did not have the same breakdown when I tried to add as sample on http://jsbin.com/ and http://jsfiddle.net/. However the Script itself works, being below the </body>. Whatever it may be, the cause, is of a nature unknown to me."
2.ª.
var A = document.getElementById('Pai'); // Div(primária)
var B = document.getElementById('Filho'); // Div(secundária)
var P = B.scrollHeight / 2;
A.onscroll = new Function("if(B.style.top = A.scrollTop + P + 'px') return true");
body {
height: 999px;
}
#Pai {
position: relative;
width: 200px;
height: 200px;
border: 3px solid blue;
text-align: center;
overflow: auto;
}
#Filho {
position: absolute;
width: 100px;
height: 100px;
top: 25%;
left: 25%;
margin: 0 auto;
background: tomato;
}
<center>
<div id='Pai'>
<p>Elemento A</p>
<p>Elemento B</p>
<p>Elemento C</p>
<p>Elemento D</p>
<p>Elemento E</p>
<p>Elemento F</p>
<p>Elemento G</p>
<p>Elemento H</p>
<p>Elemento I</p>
<p>Elemento J</p>
<div id='Filho'></div>
</div>
</center>
Jsbin - External sample
Explaining
var P = B.scrollHeight / 2;
I’m splitting up the div(secondary), by its actual size, i.e.:
Tam.: 100 2 = 50
We save this value(50) in the variable P and launch on condition if.
A.onscroll = new Function("
if(B.style.top = A.scrollTop + P) return true
");
Soon the scroll that it is linked to the element div(primary), is slided
Each "1px" will be called to new Function() for the execution
Which followed the condition if, takes action for your position
And in the blink of an eye returns true(repositioning carried out).
Ready!
Modifying the
position:absolute;forposition:fixed;not fit for your case?– Chun