Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Sebastian Limbach
1,536 PointsJavaScript "while-loop" doesn't work on Safari
Hi guys, i hope you could help me with a JavaScript problem. I just wrote a little javascript code for a parallax effect on my header image and title. It all works well in Chrome, Firefox and Opera but on Apples Safari the browser crashes instantly. Its like a endless "while-loop" but i think there isn't any endless loop. So i hope you could help me. Oh and on CodePen it also does't work:
$(document).ready(function() {
var win = $(window),
title = $('.title'),
header = $('.header'),
header_height = header.height(),
header_img = $('.header_img'),
img_height = header_img.height(),
img_diff = img_height-header_height,
i = 1,
x = header_height/i;
win.scroll(function(){
var winPos = win.scrollTop();
// Doesn't work on Safari:
if (header_img.length != 0) {
while(x > img_diff){
i = i + 0.1;
x = header_height/i;
}
}
if(winPos >= 0 && winPos <= header_height){
title.css({
top: -50 + winPos/3 + "%",
opacity: 1 - winPos/150
});
header_img.css({
top: -winPos/i
});
}
});
});
Thanks (:
1 Answer
Sebastian Limbach
1,536 PointsOk i solved the problem. I forgot the
break;