CopyPastor

Detecting plagiarism made easy.

Score: 0.76395183801651; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2018-12-27
by Dipak384

Original Post

Original - Posted on 2012-11-27
by Louis Ricci



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Try this :
function parallaxScroll(scroll) { // current moving object var ml = $moving.position().left; var mt = $moving.position().top; var mw = $moving.width(); var mh = $moving.height(); // calc velocity var fromTop = false; var fromBottom = false; var fromLeft = false; var fromRight = false; var vLeft = 0; var vTop = 0; if($moving.hasClass('from-top')) { vTop = scroll; fromTop = true; } else if($moving.hasClass('from-bottom')) { vTop = -scroll; fromBottom = true; } else if($moving.hasClass('from-left')) { vLeft = scroll; fromLeft = true; } else if($moving.hasClass('from-right')) { vLeft = -scroll; fromRight = true; } // calc new position var newLeft = ml + vLeft; var newTop = mt + vTop; // check bounds var finished = false; if(fromTop && (newTop > t || newTop + mh < t)) { finished = true; newTop = (scroll > 0 ? t : t - mh); } else if(fromBottom && (newTop < t || newTop > h)) { finished = true; newTop = (scroll > 0 ? t : t + h); } else if(fromLeft && (newLeft > l || newLeft + mw < l)) { finished = true; newLeft = (scroll > 0 ? l : l - mw); } else if(fromRight && (newLeft < l || newLeft > w)) { finished = true; newLeft = (scroll > 0 ? l : l + w); } // set new position $moving.css('left', newLeft); $moving.css('top', newTop); // if finished change moving object if(finished) { // get the next moving if(scroll > 0) { $moving = $moving.next('.parallax'); if($moving.length == 0) $moving = $view.find('.parallax:last'); } else { $moving = $moving.prev('.parallax'); if($moving.length == 0) $moving = $view.find('.parallax:first'); } } // for debug $('#direction').text(scroll + " " + l + "/" + t + " " + ml + "/" + mt + " " + finished + " " + $moving.text()); }
I hope this is helps you.
Thank you.
In a previous question I created a fairly good parallax scrolling implementation. https://stackoverflow.com/questions/12461710/jquery-parallax-scrolling-effect-multi-directional/12714412#12714412 You might find it useful.
Here's the JSFiddle http://jsfiddle.net/9R4hZ/40/ use the up/down arrows or scroll wheel.
Using padding and margin for the positioning are probably why you're experiencing rendering issues. While my code uses scroll or keyboard input for the effect you can loop the relavent portion and check the $moving variable until you reach the desired element on screen.
function parallaxScroll(scroll) { // current moving object var ml = $moving.position().left; var mt = $moving.position().top; var mw = $moving.width(); var mh = $moving.height(); // calc velocity var fromTop = false; var fromBottom = false; var fromLeft = false; var fromRight = false; var vLeft = 0; var vTop = 0; if($moving.hasClass('from-top')) { vTop = scroll; fromTop = true; } else if($moving.hasClass('from-bottom')) { vTop = -scroll; fromBottom = true; } else if($moving.hasClass('from-left')) { vLeft = scroll; fromLeft = true; } else if($moving.hasClass('from-right')) { vLeft = -scroll; fromRight = true; } // calc new position var newLeft = ml + vLeft; var newTop = mt + vTop; // check bounds var finished = false; if(fromTop && (newTop > t || newTop + mh < t)) { finished = true; newTop = (scroll > 0 ? t : t - mh); } else if(fromBottom && (newTop < t || newTop > h)) { finished = true; newTop = (scroll > 0 ? t : t + h); } else if(fromLeft && (newLeft > l || newLeft + mw < l)) { finished = true; newLeft = (scroll > 0 ? l : l - mw); } else if(fromRight && (newLeft < l || newLeft > w)) { finished = true; newLeft = (scroll > 0 ? l : l + w); } // set new position $moving.css('left', newLeft); $moving.css('top', newTop); // if finished change moving object if(finished) { // get the next moving if(scroll > 0) { $moving = $moving.next('.parallax'); if($moving.length == 0) $moving = $view.find('.parallax:last'); } else { $moving = $moving.prev('.parallax'); if($moving.length == 0) $moving = $view.find('.parallax:first'); } } // for debug $('#direction').text(scroll + " " + l + "/" + t + " " + ml + "/" + mt + " " + finished + " " + $moving.text()); }

        
Present in both answers; Present only in the new answer; Present only in the old answer;