Skip to content

Commit 593e8dc

Browse files
authored
Improve animations
1 parent 7ff59fd commit 593e8dc

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

MyProgrammingJourney.md

+8-9
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ h1 {
170170
</div>
171171

172172
<script>
173-
function setStyle(id, top, fontSize, bold, opacity){
174-
return $("#event"+id+"style").html("#event"+id+"::before{top:"+top+"px;font-size:"+fontSize+"em;color: rgba(255, 255, 255, "+bold+");opacity:"+opacity+"}\n"+"#event"+id+"::after{top:"+((5*(fontSize-1+1.5))+top)+"px;opacity:"+opacity+"}\n");
173+
function setStyle(id, top, fontSize, bold, opacity, opacity2){
174+
return $("#event"+id+"style").html("#event"+id+"::before{top:"+top+"px;font-size:"+fontSize+"em;color: rgba(255, 255, 255, "+bold+");opacity:"+opacity+"}\n"+"#event"+id+"::after{top:"+((5*(fontSize-1+1.5))+top)+"px;opacity:"+opacity2+"}\n");
175175
}
176176

177177
window.scrollTo(0, 0); //Reset Scroll
@@ -201,8 +201,6 @@ h1 {
201201
let clientRect = this.getBoundingClientRect()
202202

203203
let x1 = clientRect.top; //Distance from top of view port to top of element
204-
let x2 = (window.getComputedStyle(this, ':after').top.slice(0, -2)) / $(this).height(); //Percentage scroll of ::before and ::after
205-
let x3 = clientRect.bottom; //Distance from top of view port to bottom of element
206204

207205
if (x1 <= 250 && x1 >= 50){
208206
y1 = 1+((1-((x1-50)/200))*1); //font-size
@@ -225,19 +223,20 @@ h1 {
225223
}
226224
}
227225

228-
if (x2 > 1){
229-
y4 = ((1-((x2-1)/0.5))*1); //Opacity
226+
if (y3 > $(this).height()){
227+
y4 = (1-((y3-$(this).height())/115)); //Opacity
230228
}
231229
else{
232230
y4 = 1; //Opacity
233231
}
234232

235-
//Prevent Last element from escaping timeline
236-
if ($("li.event").length == (i+1) && y3 > $(this).height()){
233+
//Prevent Last element from escaping timeline OR prevent events from deviating too far off
234+
if (($("li.event").length == (i+1) && y3 > $(this).height()) || (y3 > $(this).height()+115)){
237235
y3 = $(this).height();
238236
}
239237

240-
setStyle(i,y3,y1,y2,y4);
238+
239+
setStyle(i,y3,y1,y2,y4,y4+1);
241240
});
242241
});
243242
</script>

0 commit comments

Comments
 (0)