scrollable获取item的当前值
我有一个可滚动的工作样本,项目编号1 – 24我想获得当前项目的价值,但我失败了。我试着去警报,但它不工作如何做到这是我的代码
更新问题:我能够获得可滚动值的索引,现在我的问题是我无法找到获取每个索引的值的方法,以获得我的代码中的索引值吗?
更新:
$(function() { // initialize scrollable with mousewheel support $(".scrollable").scrollable({ vertical: true, mousewheel: true }); $('#scroll').bind('mousewheel', function(e){ if(e.originalEvent.wheelDelta < 0) { //scroll down console.log('Down'); alert('Down'); }else { //scroll up console.log('Up'); alert('Up'); } //prevent page fom scrolling return false; }); });
我在我的js上添加了它现在正在工作,但它的输出只是向上和向下我无法找到一种方法来获得div的确切值任何建议?
scroll /* root element for scrollable */ .scrollable { /* required settings */ position:relative; overflow:hidden; /* vertical scrollables have typically larger height than width but not now */ height: 17px; width: 700px; } /* root element for scrollable items */ .scrollable .items { position:absolute; /* this time we have very large space for the height */ height:20em; } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 $(function() { // initialize scrollable with mousewheel support $(".scrollable").scrollable({ vertical: true, mousewheel: true }); });
不要使用mousewheel
事件。 而是使用onSeek
的可滚动方法。 这是一个工作示例,代码如下所示: http : //jsfiddle.net/bluegeek9bluegeek9/b5xn5/
$(document).ready(function() { $(".scrollable").scrollable({ vertical : true, mousewheel : true, onSeek : function(){ console.info("current position is: " + this.getIndex()); console.info('current value is:', $('#scroll div.items > div:nth-child(' + (this.getIndex()+1) + ') > div.item').text()); } }); });
参考