Scroll to 'irgendwo': Unterschied zwischen den Versionen
Erscheinungsbild
Die Seite wurde neu angelegt: „jQuery die aktuelle Position bestimmen lassen und danach zum nächsten/vorherigen Post/Bild/Element scrollen lassen: http://webdesignerwall.com/tutorials/scrollto…“ |
Keine Bearbeitungszusammenfassung |
||
| (7 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
jQuery die aktuelle Position bestimmen lassen und danach zum nächsten/vorherigen Post/Bild/Element scrollen lassen: | jQuery die aktuelle Position bestimmen lassen und danach zum nächsten/vorherigen Post/Bild/Element scrollen lassen: | ||
http://webdesignerwall.com/tutorials/scrollto-posts-with-jquery | http://webdesignerwall.com/tutorials/scrollto-posts-with-jquery | ||
==HTML== | |||
<nowiki><div class="post"> | |||
content... | |||
</div> | |||
<div class="post"> | |||
content... | |||
</div> | |||
<div class="post"> | |||
content... | |||
</div></nowiki> | |||
==CSS== | |||
#nav-dock { | |||
position: fixed; | |||
right: 15px; | |||
top: 35%; | |||
} | |||
==Javascript== | |||
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> | |||
<script type="text/javascript" src="js/jquery.scrollTo-min.js"></script> | |||
<script type="text/javascript"> | |||
$(function() { | |||
function scroll(direction) { | |||
var scroll, i, | |||
positions = [], | |||
here = $(window).scrollTop(), | |||
collection = $('.post'); | |||
collection.each(function() { | |||
positions.push(parseInt($(this).offset()['top'],10)); | |||
}); | |||
for(i = 0; i < positions.length; i++) { | |||
if (direction == 'next' && positions[i] > here) { scroll = collection.get(i); break; } | |||
if (direction == 'prev' && i > 0 && positions[i] >= here) { scroll = collection.get(i-1); break; } | |||
} | |||
if (scroll) { | |||
$.scrollTo(scroll, { | |||
duration: 750 | |||
}); | |||
} | |||
return false; | |||
} | |||
$("#next,#prev").click(function() { | |||
return scroll($(this).attr('id')); | |||
}); | |||
$(".scrolltoanchor").click(function() { | |||
$.scrollTo($($(this).attr("href")), { | |||
duration: 750 | |||
}); | |||
return false; | |||
}); | |||
}); | |||
</script> | |||
Keyboard-Control: | |||
http://colinelliot.posterous.com/scroll-to-posts-using-jquery-keyboard-nav | |||
// Register keypress events for the current page | |||
$(document).keypress(function(e) { | |||
switch(e.keyCode) { | |||
// User pressed "up" arrow | |||
case 38: | |||
return scroll("prev"); | |||
break; | |||
// User pressed "down" arrow | |||
case 40: | |||
return scroll("next"); | |||
break; | |||
} | |||
}); | |||
Aktuelle Version vom 6. Oktober 2012, 00:12 Uhr
jQuery die aktuelle Position bestimmen lassen und danach zum nächsten/vorherigen Post/Bild/Element scrollen lassen: http://webdesignerwall.com/tutorials/scrollto-posts-with-jquery
HTML
<div class="post"> content... </div> <div class="post"> content... </div> <div class="post"> content... </div>
CSS
- nav-dock {
position: fixed; right: 15px; top: 35%; }
Javascript
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.scrollTo-min.js"></script>
<script type="text/javascript">
$(function() {
function scroll(direction) {
var scroll, i,
positions = [],
here = $(window).scrollTop(),
collection = $('.post');
collection.each(function() {
positions.push(parseInt($(this).offset()['top'],10));
});
for(i = 0; i < positions.length; i++) {
if (direction == 'next' && positions[i] > here) { scroll = collection.get(i); break; }
if (direction == 'prev' && i > 0 && positions[i] >= here) { scroll = collection.get(i-1); break; }
}
if (scroll) {
$.scrollTo(scroll, {
duration: 750
});
}
return false; }
$("#next,#prev").click(function() {
return scroll($(this).attr('id'));
});
$(".scrolltoanchor").click(function() {
$.scrollTo($($(this).attr("href")), {
duration: 750
});
return false;
});
});
</script>
Keyboard-Control: http://colinelliot.posterous.com/scroll-to-posts-using-jquery-keyboard-nav // Register keypress events for the current page $(document).keypress(function(e) {
switch(e.keyCode) {
// User pressed "up" arrow
case 38:
return scroll("prev");
break;
// User pressed "down" arrow
case 40:
return scroll("next");
break;
}
});