less-grid-4.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. less grid v4.0 - For Less Framework 4.
  3. (c) Arnau March http://arnaumarch.com/en/lessgrid.html, freely distributable under the terms of the MIT license.
  4. */
  5. $(document).ready(function() {
  6. createSwitch();
  7. });
  8. function createGrid () {
  9. $('body').append('<div id="less-grid"></div>');
  10. var pageWidth = $('body').width();
  11. //var pageWidth = $('body').children(':first').width(); //If you don't set body width, uncomment this
  12. //var pageLeft = ($('body').width() - pageWidth) / 2; //If you don't set body width, uncomment this
  13. $('#less-grid').css({
  14. width: pageWidth,
  15. position: "absolute",
  16. top: "0",
  17. bottom: "0",
  18. zIndex: 900,
  19. //left: pageLeft //If you don't set body width, uncomment this
  20. });
  21. var colWidth = 68;
  22. var colSep = 24;
  23. var colCount = 1;
  24. for(colLeft=0;colLeft<=pageWidth;colLeft=(colWidth+colSep)*(colCount-1)){
  25. $('#less-grid').append('<span class="col col-'+colCount+'">&nbsp;col:&nbsp;'
  26. +colCount+'<br/>&nbsp;w:&nbsp;'+(((colWidth+colSep)*colCount)-colSep)+'</span>');
  27. $('#less-grid .col-'+colCount).css({
  28. width: colWidth,
  29. position: "absolute",
  30. top: "0",
  31. left: colLeft,
  32. bottom: "0",
  33. background: "#3d5fa3",
  34. opacity: 0.5,
  35. color: "#fff",
  36. fontSize: "13px",
  37. paddingTop: "33px"
  38. });
  39. colCount++;
  40. };
  41. }
  42. function createSwitch () {
  43. $('body').append('<span id="less-grid-switch">show grid</span>');
  44. $('#less-grid-switch').css({
  45. position: "absolute",
  46. top: "0",
  47. right: "0",
  48. background: "#3d5fa3",
  49. border: "2px solid #fff",
  50. borderTop: 0,
  51. color: "#fff",
  52. fontSize: "13px",
  53. lineHeight: "13px",
  54. padding: "2px 8px 6px 8px",
  55. cursor: "pointer",
  56. "border-radius": "0 0 5px 5px",
  57. "-moz-border-radius": "0 0 5px 5px",
  58. zIndex: 1000
  59. });
  60. $('#less-grid-switch').toggle(function() {
  61. $(this).text("x");
  62. $('#less-grid').show();
  63. $(this).attr('rel','on');
  64. $('#less-grid').remove();
  65. createGrid();
  66. }, function() {
  67. $(this).text('show grid');
  68. $('#less-grid').hide();
  69. $(this).attr('rel','off');
  70. });
  71. }
  72. $(function(){
  73. $(window).resize(function(){
  74. if($('#less-grid-switch').attr('rel')=="on") {
  75. $('#less-grid').remove();
  76. createGrid();
  77. }
  78. });
  79. });