


An example demonstration of a draggable column width table_javascript skills
序号 | 操作 | 标题 | 执行人 | 开始时间 | 结束时间 | 天数 |
---|---|---|---|---|---|---|
1 | 编辑 | 任务标题:阿斯卡是大家啊 | Firefox | 2012-07-15 | 2012-08-15 | 32 |
2 | 编辑 | 任务标题:阿斯卡是大家啊 | Firefox | 2012-07-15 | 2012-08-15 | 32 |
3 | 编辑 | 任务标题:阿斯卡是大家啊 | Firefox | 2012-07-15 | 2012-08-15 | 32 |
4 | 编辑 | 任务标题:阿斯卡是大家啊 | Firefox | 2012-07-15 | 2012-08-15 | 32 |
5 | 编辑 | 任务标题:阿斯卡是大家啊 | Firefox | 2012-07-15 | 2012-08-15 | 32 |
<script> <br>(function(){ //fixed table header ,还可以封装一下做成类 <br>var leftScrollPanel = $("#left-scroll-panel"); <br>var ganntBody = $("#gannt_grid>tbody"); <br>var fixedThead = leftScrollPanel.prev(".fixed-header-tb"); <br>if(!fixedThead.length){ <br>fixedThead = $('<table class="fixed-header-tb"></table>'); <br>fixedThead.append(ganntBody.prev()); <br>leftScrollPanel.before(fixedThead); <br>}else{ <br>//do not create table head again when gannt body repaint, <br>//because it is not created in function render <br>ganntBody.prev().remove(); <br>} <br>var tds = ganntBody.find("tr:first>td"); <br>var ths = fixedThead.find("th"); <br>var thWidth; <br>$.each(tds,function(index,td){ <br>//jq width() or css('width') may has 1px disparity, use attr width <br>thWidth = ths.eq(index).attr("width"); <br>(thWidth!=undefined) && $(td).attr("width",thWidth); <br>}); <br>})(); <br>(function(){//table header resize <br>var sideOffset = { <br>left:null, <br>right:null, <br>td:null, <br>tdLocked:null, <br>tdLeft:null, <br>tdRight:null <br>}; <br>var pos = { <br>resizedTime:0, <br>beginPos:0 <br>}; <br>var tableHead = $(".fixed-header-tb").find("tr:first"); <br>var headCellTagName = "th"; <br>var bodyHead = $("#gannt_grid>tbody").find("tr:first"); <br>var minInterVal = 0; <br>var minWidth = 30; <br>var borderBeside = 5; <br>var notResizeCells = [0,1,6]; <br>var freeCells = [2]; <br>var forceSize = false; <br>var resizeAllow = false; <br>var resizing = false; <br>var forbiddenResize = function(){ <br>var frag = false; <br>var o = sideOffset; <br>var index = o.td.index(); <br>if($.inArray(index,notResizeCells)>-1){ <br>frag = true; <br>}else if((index==0||$.inArray(index-1,notResizeCells)>-1)&&o.left<=borderBeside){ <BR>frag = true; <BR>}else if((index==o.td.siblings().length||$.inArray(index 1,notResizeCells)>-1)&&o.right<=borderBeside){ <BR>frag = true; <BR>}else if(o.left>borderBeside&&o.right>borderBeside){ <br>frag = true; <br>} <br>return frag; <br>}; <br>var stopResize = function(){ <br>if(!resizing){return ;} <br>resizing = false; <br>resizeAllow = false; <br>sideOffset = { <br>left:null, <br>right:null, <br>td:null, <br>tdLocked:null, <br>tdLeft:null, <br>tdRight:null <br>}; <br>}; <br>var isFreeCell = function(td){ <br>return forceSize==false && $.inArray(td.index(),freeCells)!=-1; <br>}; <br>tableHead.bind({ <br>mousemove:function(e){ <br>var th = $(e.target).closest(headCellTagName); <br>if(!th.length){ <br>return; <br>} <br>if(!resizing){ <br>sideOffset.td = th; <br>sideOffset.left = e.pageX - th.offset().left; <br>sideOffset.right = th.width()-(e.pageX-th.offset().left); <br>if(forbiddenResize()){ <br>resizeAllow = false; <br>sideOffset.td.css("cursor","default"); <br>}else{ <br>resizeAllow = true; <br>sideOffset.td.css("cursor","e-resize"); <br>pos.resizedTime = new Date()*1; <br>pos.beginPos = e.pageX; <br>} <br>return; <br>} <br>if(sideOffset.tdLocked){ <br>th = sideOffset.tdLocked; <br>} <br>if(new Date()-pos.resizedTime<minInterVal){ <BR>return; <BR>}else{ <BR>pos.resizedTime = new Date()*1; <BR>} <BR>var offset = (e.pageX-pos.beginPos); <BR>if(!offset){ <BR>return; <BR>}else{ <BR>pos.beginPos = e.pageX; <BR>} <BR>var leftWidth = sideOffset.tdLeft.width(); <BR>var rightWidth = sideOffset.tdRight.width(); <BR>if(offset<0&&leftWidth==minWidth){ <BR>return; <BR>}else if(offset>0&&rightWidth==minWidth){ <br>return; <br>} <br>var fixedLWidth,fixedRWidth; <br>if(leftWidth-Math.abs(offset)<minWidth&&offset<0){ <BR>fixedLWidth = minWidth; <BR>fixedRWidth = rightWidth - (minWidth-leftWidth); <BR>}else if(rightWidth-offset<minWidth&&offset>0){ <br>fixedRWidth = minWidth; <br>fixedLWidth = leftWidth - (minWidth-rightWidth); <br>}else{ <br>fixedLWidth = leftWidth offset; <br>fixedRWidth = rightWidth-offset; <br>} <br>var adjustCells = [ <br>{cell:sideOffset.tdLeft,width:fixedLWidth}, <br>{cell:sideOffset.tdRight,width:fixedRWidth} <br>]; <br>if(offset<0){ <br>adjustCells = adjustCells.reverse(); <br>} <br>var inOneTable = bodyHead.parents("table:first").get(0)==tableHead.parents("table:first").get(0); <br>$.each(adjustCells,function(i,cellConf){ <br>if(isFreeCell(cellConf.cell)){return;} <br>cellConf.cell.attr("width",cellConf.width); <br>if(!inOneTable){ <br>bodyHead.children().eq(cellConf.cell.index()).attr("width",cellConf.width); <br>} <br>}); <br>}, <br>mousedown:function(){ <br>if(!resizeAllow){ <br>return; <br>} <br>sideOffset.tdLocked = sideOffset.td; <br>if(sideOffset.left<=5){ <br>sideOffset.tdRight = sideOffset.td; <br>sideOffset.tdLeft = sideOffset.td.prev(); <br>}else{ <br>sideOffset.tdRight = sideOffset.td.next(); <br>sideOffset.tdLeft = sideOffset.td; <br>} <br>resizing = true; <br>return false; <br>} <br>}); <br>$(document).bind("mouseup",stopResize); <br>})(); <br></script>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use JavaScript to implement the drag and zoom function of images? In modern web development, dragging and zooming images is a common requirement. By using JavaScript, we can easily add dragging and zooming functions to images to provide a better user experience. In this article, we will introduce how to use JavaScript to implement this function, with specific code examples. HTML structure First, we need a basic HTML structure to display pictures and add

Vue is a popular JavaScript framework suitable for building single page applications (SPA). It supports drag-and-drop selection and placement functions through instructions and components, providing users with a better interactive experience. This article will introduce the techniques and best practices for drag-and-drop selection and placement in Vue. Drag Instruction Vue provides a v-draggable instruction that can easily achieve drag effects. This command can be applied to any element, and the drag style can be customized.

Vue practical skills: Use the v-on instruction to handle mouse drag events Preface: Vue.js is a popular JavaScript framework. Its simplicity, ease of use and flexibility make it the first choice for many developers. In Vue application development, handling user interaction events is an essential skill. This article will introduce how to use Vue's v-on directive to handle mouse drag events and provide specific code examples. Create a Vue instance: First, introduce the Vue.js library file in the HTML file: &

How to use Vue to implement drag-and-drop sorting effects Vue.js is a popular JavaScript framework that can help us build highly interactive front-end applications. In Vue, we can easily implement drag-and-drop sorting effects, allowing users to sort data by dragging elements. This article will introduce how to use Vue to implement drag-and-drop sorting effects, and provide specific code examples. First, we need to create an instance of Vue and define an array to store the data to be sorted. In the example we will

Vue is a popular JavaScript framework that provides a convenient drag-and-drop function, allowing us to easily copy and move elements. Next, let's take a look at how to copy and move drag-and-drop elements in Vue. 1. Basic implementation of drag-and-drop elements To copy and move drag-and-drop elements in Vue, you first need to implement the basic drag-and-drop function of the element. The specific implementation method is as follows: Add the elements that need to be dragged in the template: <divclass="drag-elem"

Vue is one of the most popular front-end frameworks today. It provides a wealth of functions and tools to help us develop various web applications conveniently. One very useful feature is drag and drop, which allows users to drag elements from one location on the page to another. Vue provides some built-in commands and functions that make it easy to create and manage drag-and-drop operations, including drag-and-drop sorting functions. This article will introduce the use and effect of the drag and drop sorting function in the Vue document. What is the drag sort function? The drag sorting function is V

How to use Layui to achieve image dragging and zooming effects. In modern web design, the interactive effect of images has become an important means to increase the vitality and user experience of web pages. Among them, image dragging and zooming effects are one of the common and popular interaction methods. This article will introduce how to use the Layui framework to achieve image dragging and zooming effects, and provide specific code examples. 1. Introduce the Layui framework and related dependencies: First, we need to introduce the Layui framework and related dependencies into the HTML file. This can be introduced via the following code example

How to use JavaScript to implement the function of dragging and dropping to change the size of elements? With the development of Web technology, more and more web pages need to have the function of dragging and dropping to change the size of elements. For example, you can drag and resize a div element to adjust its width and height. This article will introduce how to use JavaScript to achieve this function and provide specific code examples. Before we start, we need to understand some basic concepts: the position and size properties of elements: in CSS, through t
