View Single Post
Old 04-18-2011, 07:32 PM   PM User | #6
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,817
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
You just need it within the document.ready, so the document ready function includes both the slider code and the mousewheel code:

Code:
<script type="text/javascript">
$(document).ready(function()
{

  // get slider height
   var sliderHeight = $('#jQuerySlider2').height();

   // get total height of slider content
   var scrollHeight = $("#HOME-LAYER").outerHeight();

   // create content wrapper , required for scrolling 
   $('#HOME-LAYER').wrapInner('<div style="position:relative;float:left" class="layer-content-1" />');

   // make layer the same size as the slider
   //$('#HOME-LAYER').css("height", sliderHeight);

   // hide overflow
   $('#HOME-LAYER').css('overflow', 'hidden');

   // expand content
   $('.layer-content-1').css("height", scrollHeight);

   // set max value for slider
   $('#jQuerySlider2').slider("option", "min", -(scrollHeight - sliderHeight));
   $('#jQuerySlider2').slider("option", "max", 0);
   $('#jQuerySlider2').slider("option", "value", 0);

//});move the closing bracket for document-ready from here...

   // mousewheel settings
   $('#HOME-LAYER').mousewheel(function(event,delta){

   var speed = 5;//set the speed of the scroll
   var sliderVal = $("#jQuerySlider2").slider("value");//read current value of the slider
		
   sliderVal += (delta*speed);//increment the current value
 
   $("#jQuerySlider2").slider("value", sliderVal);//and set the new value of the slider
		
   var topValue = -((100-sliderVal)*difference/100);//calculate the content top from the slider position
		
   if (topValue>0) topValue = 0;//stop the content scrolling down too much
   if (Math.abs(topValue)>difference) topValue = (-1)*difference;//stop the content scrolling up too much
		
   $("#HOME-LAYER").css({top:topValue});//move the content to the new position

   event.preventDefault();//stop any default behaviour

});

})//to here...
</script>
SB65 is offline   Reply With Quote