Jump to content
Search Community

Custom mousewheel scroll with ScrollTo Plugin

Chrysto test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi Guys,

 

Just wrote a very basic script that uses TweenMax and ScrollTo plugin to animate window on scrolling with mouse wheel

 

Demo:  http://bassta.bg/demos/smooth-page-scroll/

 

Code:

<script type="text/javascript">		

			/*
				Author	: Chrysto Panayotov
				Date	: 2/28/13
			*/

			$(function(){
				
				var $window = $(window);
				var isTweening = false;
				
				document.onmousewheel = function(){ customScroll(); }
				if(document.addEventListener){
				    document.addEventListener('DOMMouseScroll', customScroll, false);
				}
				 
				function customScroll(event){
				   
				   var delta = 0;
				   
				   if (!event){
					   event = window.event;
				   }
				   
				   if (event.wheelDelta) {
					   delta = event.wheelDelta/120;
				   } else if(event.detail) {
					   delta = -event.detail/3;
				   }
				   
				   if (delta){
				   		
				   		//console.log(isTweening);
				   		
				   		//if(!isTweening){
					   		
					   		//isTweening = true;
					   		
						   	var scrollTop = $window.scrollTop();
						   	var finScroll = scrollTop - parseInt(delta*100) * 3;
						   
						   	//console.log(finScroll);
						   	   					   			   
						   	TweenMax.to($window, 0.5, {
							   	scrollTo : { y: finScroll, autoKill:true },
							   	ease: Power4.easeOut,
							   	autoKill: true,
							   	overwrite: 5,
							   	onComplete: function(){ 
							   		//console.log(isTweening);
							   		//isTweening = false; 
							   	}
							});
					   
					   //}
				   }
				   
				   if (event.preventDefault){
					   event.preventDefault();
				   }
				   
				   event.returnValue = false;
				     				    
				}
				
			});

		</script>

This is just an concept, but it is helpfull for somebody :)

tweenlitemousewheel.zip

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...