Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.66 KB  |  hits: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. dragging in Jquery mouse down event?
  2. <style>
  3. .Selected{
  4. background-color :red;
  5. }
  6.  
  7. </style>
  8.  
  9. <script>
  10.      $(document).ready(function() {
  11.  
  12.  $('#WeekTable td').live('click', 'td', function() {
  13. $(this).toggleClass('Selected');
  14.                 });
  15.  
  16. $('#Which').click(function() {
  17. $('.Selected').each(function(index){
  18. alert($(this).attr("ID"));
  19. })
  20.                 });
  21.  
  22.                 });
  23.  
  24. </script>
  25. <table id="WeekTable" >
  26. <tr id="WeekRow">
  27. <td value = "1" id="Week1">1</td>
  28. <td value = "2" id="Week2">2</td>
  29. <td value = "3" id="Week3">3</td>
  30. <td value = "4" id="Week4" >4</td>
  31. <td value = "5" id="Week5">5</td>
  32. <td value = "6" id="Week6">6</td>
  33. <td value = "7" id="Week7">7</td>
  34. <td value = "8" id="Week8">8</td>
  35. <td value = "9" id="Week9">9</td>
  36. <td value = "10" id="Week10">10</td>
  37. <td value = "11" id="Week11">11</td>
  38. <td value = "12" id="Week12">12</td>
  39. <td value = "13" id="Week13">13</td>
  40. <td value = "14" id="Week14">14</td>
  41. <td value = "15" id="Week15">15</td>
  42. </tr>
  43. </table>
  44. <button id="Which" >Which Weeks?</button>
  45.        
  46. mouseIsDown = false;
  47.  
  48. $(window).mousedown(function(){
  49.     mouseIsDown = true;
  50. });
  51.  
  52. $(window).mouseup(function(){
  53.     mouseIsDown = false;
  54. });
  55.        
  56. $("#WeekTable td").hover(function(){
  57.     if(mouseIsDown) $(this).addClass("Selected");
  58. });
  59.        
  60. $("#WeekTable td").click(function(){
  61.     $(this).toggleClass('Selected');
  62. });
  63.        
  64. $(document).ready(function() {
  65.     var dragging = false;
  66.  
  67.     $('html').mousedown(function(e){
  68.         dragging = true;
  69.     })
  70.     $('html').mouseup(function(e){
  71.         dragging = false;
  72.     });
  73.  
  74.     $('#WeekTable tr td').mouseover(function(e){
  75.         if (dragging) {
  76.             $(this).css('background-color', 'red');
  77.         }
  78.     });
  79. });​