Advertisement
To-Slalom

grids

Jun 18th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <!doctype html>
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <link href="sticky.css" rel="stylesheet" type="text/css">
  9. <title>MiniMasonry.js: Masonry Layout Demo</title>
  10. <meta name="referrer" content="origin"/>
  11. <meta name="referrer" content="origin-when-crossorigin"/>
  12. <meta name="referrer" content="origin-when-cross-origin"/>
  13.  
  14. <script>
  15. /*
  16. var items = ['a', 'b', 'c'];
  17. for (  i=0; i<items.length; i++) {
  18.   alert(items[i])
  19. }
  20. var str = "The rain in SPAIN stays mainly in the plain";
  21. var res = str.match(/ain/g);
  22.   alert(res )
  23.  
  24. var reg = /div/g, // regexp for an image element
  25. query = document.querySelector('.class1'); // returns [object HTMLImageElement]
  26. query += this.toString(); // turns object into a string
  27.  
  28. if (query.match(reg)) { // checks if it matches
  29.   alert('the class .bar is attached to the following Element:\n' + query);
  30.  
  31. }
  32. */
  33. </script>
  34. </head>
  35. <body>
  36. <!--
  37. https://stackoverflow.com/questions/507138/how-do-i-add-a-class-to-a-given-element
  38. IE code resize
  39. -->
  40. <h1 id="id1">My Heading 1</h1>
  41. <div class="col-9">Found.</div>
  42.  
  43. <div class="col-6">nothing happens hear.</div>
  44. <div class="col-6">nothing happens hear.</div>
  45. <div class="class1 col-6">This element will receive yout code.</div>
  46. <div class="class1 col-3">This element will receive yout code.</div>
  47. <div class="class1 col-2"> col-xs-2  col-2 </div>
  48. <div class="class1 col-1">This element will receive yout code.</div>
  49. <div id="test" class="class1 class5"></div>
  50. <p id="demo"></p>
  51.  
  52. <script type="text/javascript">
  53. function function_one()
  54. {
  55.    // alert("The function called 'function_one' has been called.")
  56.     //Here u would like to call function_two.
  57.     function_two();
  58. }
  59. // Pessoal muito jรก sabem que estou a fazer uma encomenda,.... e como vou ter mais uma pessoal interessada
  60. function function_two() {
  61.     //alert ("<p> checkWinWH " + checkWinWH() + "  </p> " ) ;
  62.     // achar o numero de divs que a paguina tem
  63.     var array = FindClassNames ( 'div' ) ;
  64.     //alert(array);
  65.     var count =  array.length ;
  66.    // alert(count);
  67.  
  68.     //check each span element for class 'italic' or 'bold'
  69.     for ( var i = 0 ; i < count ; i++ ) {
  70.         var AllClass = array[i].className ;
  71.         //alert("<p>" + AllClass + "</p>");
  72.         // agora vou separar as class para achar a que quero de acordo com a largura da janela
  73.         var strSplit = AllClass.split(" ") ;
  74.         if ( strSplit.length > 1 ) {
  75.             for ( var a = 0 ; a < strSplit.length ; a++ ) {
  76.                 var singleClass = strSplit[a] ;
  77.                 //alert ( singleClass ) ;
  78.             }
  79.         }
  80.         else {
  81.             AddCssStyleViaClass ( AllClass , "width:100%;" ) ;
  82.                 var nxt = AllClass;
  83.            nxt = undefined; // unset
  84.       delete(nxt); // this removes the variable completely
  85.         }
  86.     }
  87. }
  88.  
  89. function FindClassNames ( TagName ) {
  90.     var array = document.getElementsByTagName ( TagName ) ; // get all span elements
  91.     var found = [] ;
  92.     for ( var i = 0 ; i < array.length ; i++ ) {
  93.         var names = array[i].className ;
  94.         found.push ( array[i] ) ;
  95.     }
  96.     return found ;
  97. }
  98. /*
  99.     //document.write("<p> found " + founds + " " + TagName + " tags </p> " ) ;
  100.     for ( var i = 1 ; i <= 12 ; i++ ){
  101.         //alert("<p> col-md-"+i1+"</p>");
  102.         //document.write("<p> col-md-"+i+"</p>");
  103.         document.getElementById("demo").innerHTML = "<p> col-md-"+i+"</p>" ;
  104.     }
  105. */
  106. function checkWinWH() {
  107.     var viewportwidth , viewportheight ;
  108.     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
  109.     if ( typeof window.innerWidth != 'undefined' ) {
  110.         viewportwidth  = window.innerWidth,
  111.         viewportheight = window.innerHeight
  112.     }
  113.     // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
  114.     else if (
  115.         typeof document.documentElement             != 'undefined' &&
  116.         typeof document.documentElement.clientWidth != 'undefined' &&
  117.                document.documentElement.clientWidth != 0 ) {
  118.                 viewportwidth  = document.documentElement.clientWidth,
  119.                 viewportheight = document.documentElement.clientHeight
  120.     } // older versions of IE
  121.     else {
  122.         viewportwidth  = document.getElementsByTagName('body')[0].clientWidth,
  123.         viewportheight = document.getElementsByTagName('body')[0].clientHeight
  124.     }
  125.     return viewportwidth ;
  126.     /*
  127.     if ( document.body && document.body.offsetWidth ) {
  128.         winW = document.body.offsetWidth;
  129.         winH = document.body.offsetHeight;
  130.     }
  131.     if (
  132.         document.compatMode=='CSS1Compat' &&
  133.         document.documentElement &&
  134.         document.documentElement.offsetWidth ) {
  135.             winW = document.documentElement.offsetWidth  ;
  136.             winH = document.documentElement.offsetHeight ;
  137.     }
  138.     if ( window.innerWidth && window.innerHeight ) {
  139.         winW = window.innerWidth;
  140.         winH = window.innerHeight;
  141.     }
  142.  
  143.     alert('Window width = '+winW+' Window height = '+winH);
  144.     alert('Window width = '+viewportwidth+' Window height = '+viewportheight);
  145.  
  146.     var color = ( viewportwidth > 400 ) ? 'red' : 'blue' ;
  147.     var color2 = ( viewportwidth < 400 ) ? 'green' : 'yellow' ;
  148.     document.getElementById('id1').style.color = color ;
  149.     AddCssStyleViaClass ( "asdf" , "color:"+color+"; border: 1px solid "+color2+";" ) ;
  150.     */
  151. }
  152.  
  153. function getElementsByClassNames ( className ) {
  154.     var found    = [] ;
  155.     var elements = document.getElementsByTagName( "*" ) ;
  156.     for ( var i = 0 ; i < elements.length ; i++ ) {
  157.         var names = elements[i].className.split ( ' ' ) ;
  158.         for ( var j = 0; j < names.length ; j++ ) {
  159.             if ( names[j] == className ) found.push ( elements[i] ) ;
  160.         }
  161.     }
  162.     return found ;
  163. }
  164. /* funcao para dar suporte ao firefox abaixo do 4
  165.     como usar
  166.     var e = getElementsByClassNames("YourClassName");
  167.     //alert(e[0].innerHTML);
  168.     e[0].setAttribute("style", "color:"+color+"; border: 1px solid "+color+";");
  169. */
  170. function AddCssStyleViaClass ( ClassName , setAttributeData ) {
  171.     var e = getElementsByClassNames ( ClassName ) ;
  172.     return e[0].style.color = "blue";
  173.     //return e[0].setAttribute ( "style" , setAttributeData ) ;
  174. }
  175.  
  176. //window.onload=checkWinWH ;
  177. window.onload=function_one ;
  178. window.onresize=window_resize ;
  179. var resizeTimeoutId;
  180. function window_resize(e) {
  181.     window.clearTimeout(resizeTimeoutId);
  182.     resizeTimeoutId = window.setTimeout('function_one();', 100);
  183.     // resizeTimeoutId = window.setTimeout('checkWinWH();', 100);
  184. }
  185.  
  186. </script>
  187.  
  188. </body>
  189. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement