Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

add handleWheel 增加picker区域鼠标滚动选择 #593

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/js/photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
}

var self = this;
this.modal.show().height();
this.modal.addClass('weui-photo-browser-modal-visible');
this.container.addClass('swiper-container-visible').transitionEnd(function() {
self.initParams();
if(index !== undefined) {
Expand All @@ -62,6 +60,8 @@
self.config.onOpen.call(self);
}
});
this.modal.show().height();
this.modal.addClass('weui-photo-browser-modal-visible');

this._open = true;
},
Expand Down
23 changes: 23 additions & 0 deletions src/js/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,33 @@
var value = $(this).attr('data-picker-value');
col.setValue(value);
}

function handleWheel(e){
allowItemClick = false;
$.cancelAnimationFrame(animationFrameId);

var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) || (e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1));
var newPickerVal, valuecurrent, currentElement = $(col.items[col.activeIndex]);
newPickerVal = valuecurrent = currentElement.attr('data-picker-value');
if(delta>0 && (col.activeIndex !== 0)){
newPickerVal = currentElement.prev().attr('data-picker-value');
}else if(delta<0 && (col.activeIndex !== (col.items.length-1))){
newPickerVal = currentElement.next().attr('data-picker-value');
}
(newPickerVal!=valuecurrent)&&col.setValue(newPickerVal);

// Allow click
setTimeout(function () {
allowItemClick = true;
}, 100);
}

col.initEvents = function (detach) {
var method = detach ? 'off' : 'on';
col.container[method]($.touchEvents.start, handleTouchStart);
col.container[method]($.touchEvents.move, handleTouchMove);
col.container[method]($.touchEvents.end, handleTouchEnd);
col.container[method]("wheel mousewheel DOMMouseScroll", handleWheel);
col.items[method]('click', handleClick);
};
col.destroyEvents = function () {
Expand Down Expand Up @@ -635,6 +656,8 @@
dialog.width(); //通过取一次CSS值,强制浏览器不能把上下两行代码合并执行,因为合并之后会导致无法出现动画。

dialog.addClass("weui-picker-modal-visible");

dialog[0].addEventListener('mousewheel',function(e){e.preventDefault();}); //picker选项区域禁止鼠标滚动

callback && container.on("close", callback);

Expand Down