Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animate scrolling with CSS3

Is there a way to animate scrolling with CSS3?

Something like this?

@-webkit-keyframes scrolltoview
{
    0%   { scrollTop: 0; }
    100% { scrollTop: 30%; }
}

How to put in the css where's the staring point of the animation?

like image 218
Spiff Avatar asked Apr 21 '12 16:04

Spiff


People also ask

Can you animate using CSS?

CSS animations make it possible to animate transitions from one CSS style configuration to another. Animations consist of two components, a style describing the CSS animation and a set of keyframes that indicate the start and end states of the animation's style, as well as possible intermediate waypoints.

How do I make text appear on scroll in HTML?

First wrap whatever your text or content that you want to show on scroll, in one div so that you can show hide the div depending upon the scroll. Write two classes for your target div. Aside from the jQuery, this is definitely the best thought-out and helpful answer.


1 Answers

As explained here you can do it using margin-top trick and updating scroll position dynamically. You can check the demo. Code is straight forward:

// Define the variables
var easing, e, pos;
$(function(){
  // Get the click event
  $("#go-top").on("click", function(){
    // Get the scroll pos
    pos= $(window).scrollTop();
    // Set the body top margin
    $("body").css({
      "margin-top": -pos+"px",
      "overflow-y": "scroll", // This property is posed for fix the blink of the window width change 
    });
    // Make the scroll handle on the position 0
    $(window).scrollTop(0);
    // Add the transition property to the body element
    $("body").css("transition", "all 1s ease");
    // Apply the scroll effects
    $("body").css("margin-top", "0");
    // Wait until the transition end
    $("body").on("webkitTransitionEnd transitionend msTransitionEnd oTransitionEnd", function(){
      // Remove the transition property
      $("body").css("transition", "none");
    });
  });
});

@AndrewP provided a nice working example based on this idea

like image 93
mente Avatar answered Sep 25 '22 00:09

mente