JS / jq imitation WINDOW folder box selection plugin

0. Let’s see the effect:

js/jq仿window文件夹框选操作插件 1. Create an index.html file


  Title   UL {List-style: none} Li {Width: 200PX; Margin: 10px; float: Left; Height: 100px Background: #ccc; border: 1px solid #fff;} .selected {border: 1px solid red}           
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • 2. Introducing Plug-in Areaselect.js
  • JS / jq imitation WINDOW folder box selection plugin插图1
  • (Function ($) {$ .fn.areaselect = function ( OPTION {var Opt = {} OPT = $. extend (OPT, Option); var _this = $ (this_this.on ('mousedown', function (e) {console.log (_this) _this.find ('li'). RemoveClass ('SELECTED'); var starttop = E.Pagey; var startleft = E.Pagex Var endtop, endleft; var selectbox = $ ('
  • JS / jq imitation WINDOW folder box selection plugin插图1'); $ ('body'). Append (selectbox); selectBox.css ({'position': 'absolute', 'top ": Starttop + 'PX', 'Left': Startleft + 'PX', 'Background': 'RGBA (255, 106, 23, 0.3)', 'Transition': 'All 0S', 'Width': 0, 'Height': 0, 'z-index': 10} $ (document) .on ('mousemove', function (e) {E.PREVENTDEFAULT (); endtop = e.pagey; endlex = e.pagex; if (E.Pagey-StartTop > 0 && E.PAGEX-StartLeft> 0) {var height = E.pagey-starttop; var width = E.Pagex-startLeft; selectBox.css ({'width': WIDTH + 'PX', 'Height': Height + 'PX'}}}}} Else IF (E.Pagey-StartTop
  • 0 && E.Pagex-StartLeft
    0) {var height = - (E.Pagey-StartTop ); var width = (e.pagex-startleft); selectBox.css ({'width': width + 'px', 'height': height + 'px', 'top': E.Pagey + 'PX', 'Left' : StartLeft + 'PX'}}} _this.find ('> Li'). Each (Function () {IF ((StartLeft
    StartTop && (E.Pagey-StartTop> 0 && E.Pagex-StartLeft> 0) ) || (Endleft
endtop && (E.Pagey-StartTop StartTop && (E.Pagey-StartTop> 0 && E.Pagex-StartLeft Endtop && (E.Pagey-StartTop
0 ))) {$ (this) .addclass ('SELECTED'); return;} else {$ (this) .removeClass ('SELECTED');}})}}) $ (document) .on ('mouseup', function () {// if (opt.do) Opt.do (); Perform Destruction Function Or, hook function $ ('# select-box'). Remove (); $ (document) .unbind ('mousemove');})})}} (jQuery)


3. Calling plug-in

At the bottom of Index.html, the bottom adds the following code:
  
<0 && e.pageX-startLeft $ ( Function () {$ ('. Test'). Areaselect ()}) <0) { var height=(e.pageY-startTop); var width=-(e.pageX-startLeft); selectBox.css({ 'width':width+'px', 'height':height+'px', 'top':startTop+'px', 'left':e.pageX+'px' }) }else if(e.pageY-startTop <$(this).offset().left+$(this).width() && $(this).offset().left<endLeft && $(this).offset().top <$(this).offset().left+$(this).width() && $(this).offset().left<startLeft && $(this).offset().top <0 && e.pageX-startLeft<0)) || (endLeft<$(this).offset().left+$(this).width() && $(this).offset().left<startLeft && $(this).offset().top Open INDEX.html View Effect! ! ! ! <0)) || (startLeft<$(this).offset().left+$(this).width() && $(this).offset().left<endLeft && $(this).offset().top The above is the JS / JQ imitation of the WINDOW folder box to give you a small package, I hope that everyone can help, if you have any questions, please leave a message, the small package will reply in time. Ours. Thank you very much for your support of Tumi Cloud Website!
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment