I play with scrolling, etc. for several hours today and came up with what, in my opinion, is a neat scroll frame without scroll bars, similar to what was suggested here. It scrolls vertically, either a “page” at a time, or a specific item (such as a DIV). It also scrolls horizontally, either a page at a time, or a specific item (for example, SPAN).
Look at the action in this fiddle
HTML example:
<p> <h1>Vertical scrolling</h1> <button class="shift up" value="updown" >^</button> <button class="shift vertical" value="updown Av">A</button> <button class="shift vertical" value="updown Bv">B</button> <div id="updown"> <div id="Av"> AAAAAAA text AAAAAAA </div> <div id="Bv"> BBBBBBB text BBBBBBB </div> <div id="Cv"> CCCCCCC text CCCCCCC </div> <div id="Mv"> MMMMMMM text MMMMMMM </div> </div> <button class="shift down" value="updown" >v</button> <button class="shift vertical" value="updown Cv">C</button> <button class="shift vertical" value="updown Mv">M</button> </p> <p> <h1>Horizontal scrolling</h1> <button class="shift right" value="leftright" >></button> <button class="shift horizontal" value="leftright Ah">A</button> <button class="shift horizontal" value="leftright Bh">B</button> <div id="leftright"> <span id="Ah"> AAAAAAA text AAAAAAA </span> <span id="Bh"> BBBBBBB text BBBBBBB </span> <span id="Ch"> CCCCCCC text CCCCCCC </span> <span id="Mh"> MMMMMMM text MMMMMMM </span> </div> <button class="shift left" value="leftright"><</button> <button class="shift horizontal" value="leftright Ch">C</button> <button class="shift horizontal" value="leftright Mh">M</button> </p>
CSS:
#updown, #leftright{ position: relative; overflow: hidden; line-height: 1.5em; height: 1.5em; width: 20em; border: 2px solid #000; } #updown div { position: absolute; height: 1.5em; width: 20em; margin: 0; padding: 0; border: 0; } #leftright span { position: absolute; display: inline; float: left; height: 1.5em; width: 20em; margin: 0; padding: 0; border: 0; }
javascript:
// See it in action at http://jsfiddle.net/Q7FFN/ $('#updown div').each(function(i){ // position the "divs" var $this = $(this); var amount = $this.parent().height(); $this.css({top: i * amount}); }); $('#leftright span').each(function(i){ // position the "spans" var $this = $(this); var amount = $this.parent().width(); $this.css({left: i * amount}); }); $('.shift').click(function(){ var $this = $(this); var value = $this.attr('value'); var values = value.split(/ +/); var items = '#' + values[0]; var item = (values.length == 2) ? '#' + values[1] : ''; var classes = $this.attr('class'); if (classes.match(/\bup\b/)) { // up - Use "match" instead of hasClass() for performance var amount =$(items).height(); $(items).children().animate({top: '-=' + amount}, 'slow'); } else if (classes.match(/\bdown\b/)) { // down var amount =$(items).height(); $(items).children().animate({top: '+=' + amount}, 'slow'); } else if (classes.match(/\bleft\b/)) { // left var amount = $(items).width(); $(items).children().animate({left: '-=' + amount}, 'slow'); } else if (classes.match(/\bright\b/)) { // right var amount = $(items).width(); $(items).children().animate({left: '+=' + amount}, 'slow'); } else if (classes.match(/\bvertical\b/)) { // vertical var amount = $(item).css('top'); console.log("amount=", amount); $(items).children().animate({top: '-=' + amount}, 'slow'); } else if (classes.match(/\bhorizontal\b/)) { // horizontal var amount = $(item).css('left'); $(items).children().animate({left: '-=' + amount}, 'slow'); } else { return false; } });
source share