JS - 水平滚动

时间:2016-10-26 14:55:39

标签: javascript jquery css css3 scrollbar

尝试在某个列表上进行水平滚动,但是我收到错误 - ''未捕获TypeError:$(...)。mousewheel不是函数''。 我的JS是:

<script>
$(document).ready(function () {
$('.item-list').mousewheel(function(e, delta) {
    this.scrollLeft -= (delta * 40);
    e.preventDefault();
});

});

</script>
<script type='text/javascript' src='/wp-content/themes/engrave-lite-child/js/jquery.mousewheel.js'></script>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>

2 个答案:

答案 0 :(得分:1)

在 jQuery源代码后添加 override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? { if indexPath.row == 1 { var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell1 ") as YourTableViewCell return cell } else if indexPath.row == 2 { var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell2 ") as YourTableViewCell return cell } //do this to maintain the same cells at position 1..4 and for the rest of the rows else { var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell5 ") as YourTableViewCell return cell } } 源文件

&#13;
&#13;
jquery.mousewheel.js
&#13;
.item-list {
  overflow: auto;
  width: 100%;
}
.i-con {
  width: 3000px;
  background: orange;
  height: 100px;
}
&#13;
&#13;
&#13;

答案 1 :(得分:0)

在加载库之前使用mousewheel()! 你应该把你的自定义脚本标签放在库之后。

你也可以(非强制性地)通过在dom ready和init回调中调用它来推迟库的加载,当你知道它被加载时肯定:

$(document).ready(function () {
    $.get('/wp-content/themes/engrave-lite-child/js/jquery.mousewheel.js', function(){
        $('.item-list').mousewheel(function(e, delta) {
            this.scrollLeft -= (delta * 40);
            e.preventDefault();
        });
    });
});