Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery pligin中的Javascript mouseheel函数_Javascript_Jquery_Html - Fatal编程技术网

jQuery pligin中的Javascript mouseheel函数

jQuery pligin中的Javascript mouseheel函数,javascript,jquery,html,Javascript,Jquery,Html,我有以下几把小提琴: 正如您所看到的,我有两个ul元素,它们带有li,正在按步骤滚动 但当我在jQuery插件中使用它时,它不会滚动步骤,它不会执行任何操作: (function ( $ ) { $.fn.timeshift = function( options ) { var defaults = { height: 35, hourClock: 24, steps: 15, startTime: 0, endTime

我有以下几把小提琴:

正如您所看到的,我有两个
ul
元素,它们带有
li
,正在按步骤滚动

但当我在jQuery插件中使用它时,它不会滚动步骤,它不会执行任何操作:

(function ( $ ) {
  $.fn.timeshift = function( options ) {

    var defaults = {
      height: 35,
      hourClock: 24,
      steps: 15,
      startTime: 0,
      endTime: 23,
      wrapperAttrs : {
        class: "timeshift-placeholder"
      },
    };

    var filteredOptions = {};
    $.each(options, function( index, value ) {
      if (index in defaults === true) {
        filteredOptions[index] = value;
      }
    });

    var settings = $.extend( {}, defaults, filteredOptions );

    var timeSheet =
      {
        0: 12,
        1: 1,
        2: 2,
        3: 3,
        4: 4,
        5: 5,
        6: 6,
        7: 7,
        8: 8,
        9: 9,
        10: 10,
        11: 11,
        12: 12,
        13: 1,
        14: 2,
        15: 3,
        16: 4,
        17: 5,
        18: 6,
        19: 7,
        20: 8,
        21: 9,
        22: 10,
        23: 11
      };

    var hourElement = $('<ul id="hours"></ul>');
    for (var i = 0; i <= 23; i++) {
      var hourValue = (settings.hourClock === 24? i:timeSheet[i]);

      var element = $('<li class="timeItem">'+hourValue+'</li>');
      hourElement.append(element);
    }

    var minuteElement = $('<ul id="minutes"></ul>');
    for (var i = 0; i <= 59; i++) {
      var element = $('<li class="timeItem">'+i+'</li>');
      minuteElement.append(element);
    }

    var scrollHeight = 0;
    minuteElement.bind('mousewheel', function(event) {
      var scrollPosition = $(this).scrollTop();
      if (event.originalEvent.wheelDelta >= 0) {
        if (scrollPosition <= scrollHeight) {
          $(this).scrollTop(scrollHeight - settings.height);
          scrollHeight = $(this).scrollTop();
        }
      } else {
        if (scrollPosition <= scrollHeight) {
          $(this).scrollTop(scrollHeight + settings.height);
          scrollHeight = $(this).scrollTop();
        }
      }
    });

    hourElement.bind('mousewheel', function(event) {
      var scrollPosition = $(this).scrollTop();
      if (event.originalEvent.wheelDelta >= 0) {
        if (scrollPosition <= scrollHeight) {
          $(this).scrollTop(scrollHeight - settings.height);
          scrollHeight = $(this).scrollTop();
        }
      } else {
        if (scrollPosition <= scrollHeight) {
          $(this).scrollTop(scrollHeight + settings.height);
          scrollHeight = $(this).scrollTop();
        }
      }
    });

    this.append(hourElement);
    this.append(minuteElement);

    var timeshift = this
      .attr(settings.wrapperAttrs)
      .css('min-height', settings.height)
      .css('max-height', settings.height)
      .css('height', settings.height);
    return timeshift;

  };

}( jQuery ));
(函数($){
$.fn.timeshift=功能(选项){
var默认值={
身高:35,
小时锁定:24,
步骤:15,
开始时间:0,
完时间:23,,
包装器属性:{
类:“timeshift占位符”
},
};
var filteredOptions={};
$.each(选项、函数(索引、值){
if(默认值中的索引===true){
filteredOptions[索引]=值;
}
});
变量设置=$.extend({},默认值,filteredOptions);
var时间表=
{
0: 12,
1: 1,
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
10: 10,
11: 11,
12: 12,
13: 1,
14: 2,
15: 3,
16: 4,
17: 5,
18: 6,
19: 7,
20: 8,
21: 9,
22: 10,
23: 11
};
var hourement=$('
    ); 对于(变量i=0;i=0){
    如果(scrollPosition您的滚动代码缺少
    事件.preventDefault();
    ,因此滚动行为类似于正常滚动,因此您将滚动设置为给定值,但滚动事件保持其正常行为。您必须插入preventDefault

    例如:

        hourElement.bind('mousewheel', function(event) {
          var scrollPosition = $(this).scrollTop();
              console.log('scrollPosition', scrollPosition);
          if (event.originalEvent.wheelDelta >= 0) {
            if (scrollPosition <= scrollHeight) {
              $(this).scrollTop(scrollHeight - settings.height);
              scrollHeight = $(this).scrollTop();
              event.preventDefault();
            }
          } else {
            if (scrollPosition <= scrollHeight) {
              $(this).scrollTop(scrollHeight + settings.height);
              scrollHeight = $(this).scrollTop();
              event.preventDefault();
            }
          }
        });
    
    hourement.bind('mousewheel',函数(事件){
    var scrollPosition=$(this.scrollTop();
    console.log('scrollPosition',scrollPosition);
    如果(event.originalEvent.wheelDelta>=0){
    
    如果(scrollPosition)可以将你的代码插入到一个工作示例中,这样就更容易复制和理解你的问题了?你是什么意思?我想有一个类似于选择框的功能。但是,与ul列表相比。当你使用鼠标滚轮时,它必须捕捉到每个数字(li)我做了一些小改动。当我将左边的滚动到5,而不是右边的滚动时,由于变量scrollHeigt: