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?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With