jquery - Scroll a div horizontally in an other div -


i want reproduce (which work perfectly) :

http://jsfiddle.net/pvvdq/

but don't want apply on document.height, on div height.

this script have

if(positionydiapo<=middleheight){          $('#frame').css({position:'fixed', top: positiontop - $(window).scrolltop(), bottom:'auto'}).addclass('stuck').removeclass('anchored');               if(bottomdiapo<=bottomframe){                 $('#frame').css({ 'position': 'absolute' });                 $('#frame').css({ 'bottom': '0px' });                 $('#frame').css({ 'top': 'auto' });                 $('#frame').removeclass('stuck').addclass('anchored');             }              var $horizontal = $('#frame');              var s = $(this).scrolltop(),                 d = $(document).height(),                 c = $(this).height();              scrollpercent = (s / (d - c));              var position = (scrollpercent * ($(document).width() - $horizontal.width()));              $horizontal.css({'left': position});              var st = $(this).scrolltop();        if (st > lastscrolltop){            // downscroll code            console.log('down');        } else {           // upscroll code            if((bottomframe)-hauteurdiv>=middleheight){              console.log('up');              $('#frame').css({position:'fixed', top: positiontop - $(window).scrolltop(), bottom:'auto'}).addclass('stuck').removeclass('anchored');             }        }        lastscrolltop = st;         }else{         console.log('no code here');         $('#frame').css({position:'absolute', top:'0px', bottom:'auto'}).removeclass('stuck').removeclass('anchored');     } 

plus, need keep track of left position when action stop

well, need change first referenced document div scroll apply to.

javascript has 2 handy functions determining widths , lengths called:

you can implement these functions in jquery altering function this:

$(document).ready(function () {     var $horizontal = $('#horizontal');      $('#test').scroll(function () {         var s = $(this).scrolltop(),             d = $('#test').get(0).scrollheight,             c = $('#test').get(0).scrollwidth,          scrollpercent = (s / (d - c));          var position = (scrollpercent * (c - 2*$horizontal.width()));          $horizontal.css({             'left': position         });     }); }); 

(i didn't check if calculations absolutely correct might want that)

with corresponding html structure:

<div id="test">  // put content here  </div>  <div id="horizontal">scrolling div</div> 

you can find implementation of code in jsfiddle.

i hope gets started. luck!


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -