5 Star 10 Fork 1

liu / horiz-split-box.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
horiz-split-box.js 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
liu 提交于 2017-03-13 10:47 . 添加触控支持
(function ($) {
$.fn.horizSplitBox = function() {
var $box = $(this);
var $cover = $box.find('.cover');
var $toggle = $box.find('.toggle-handle');
var mouseX, toggleLeft, draggable = false;
function getPageX(e) {
if (typeof e.pageX == 'undefined' ) {
return e.touches[0].pageX;
}
return e.pageX;
}
$(document).on('mousemove touchmove', function (e) {
if (!draggable) {
return;
}
var left = toggleLeft + getPageX(e) - mouseX;
var width = $toggle.parent().width() - $toggle.width();
left = Math.max(Math.min(left, width), 0);
$toggle.css('left', left);
$cover.css('width', left);
});
$(document).on('mouseup touchend', function (e) {
draggable = false;
$box.css('user-select', '');
});
$toggle.on('mousedown touchstart', function (e) {
draggable = true;
mouseX = getPageX(e);
toggleLeft = $toggle.position().left;
$box.css('user-select', 'none');
});
return $box;
}
})(jQuery);
JavaScript
1
https://gitee.com/lc-soft/horiz-split-box.git
git@gitee.com:lc-soft/horiz-split-box.git
lc-soft
horiz-split-box
horiz-split-box.js
master

搜索帮助