Horizontal Parallax Scrolling from Scratch - No Plugin (jQuery)

后端 未结 3 459
情深已故
情深已故 2021-02-04 21:27

Does anyone know were I can find a tutorial for how to do horizontal parallax scrolling via js form scratch (i.e. no plug-in)? Or can provide me with an example

I\'ve sp

3条回答
  •  臣服心动
    2021-02-04 22:11

    Here's a crudely simple implementation of parallax scrolling: http://jsfiddle.net/4kG6s/

    function AnimateMe(){
        $("#background").css("background-position", "-=2");
        $("#middleground").css("background-position", "-=4");
        $("#foreground").css("background-position", "-=8");    
    }
    
    setInterval(AnimateMe, 100);
    

    While this implementation is animating the background-position, the concept remains the same. The foreground moves proportionally faster than the background, and there are layers stacked on top of eachother. Conceptually, that's as simple as it gets.

提交回复
热议问题