Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. <div id="dynamic-gradient">
  2. <header class="grid-pad">
  3. <h2>Dynamic Gradients</h2>
  4.  
  5. <p>
  6. PHP loop that adjusts the linear-gradient based on the $index. Utilises the Masonry JavaScript library for jazzing up the responsive aspect. Design-wise, I've nicked a bit from Google's Material Design documentation.
  7. </p>
  8. </header>
  9. <section id="gradient-wrapper">
  10. <?php
  11. for ($i = 0; $i <= 10; $i++) {
  12. $title = array(
  13. 'Article Title',
  14. 'Longer Article Title',
  15. 'Art Tit',
  16. 'Article Title: With an extra bit',
  17. 'Long Article Title',
  18. 'Numbered Article Title #6',
  19. 'Seventh Article Title',
  20. 'This is possibly the longest of all of the Article Titles that I can possibly write',
  21. 'Le title d\'article numero neuf',
  22. 'Article Title',
  23. 'Another Article Title',
  24. 'Longer Article Title',
  25. 'Seventh Article Title',
  26. 'Art Tit',
  27. 'Article Title: With an extra bit',
  28. 'Long Article Title',
  29. 'Numbered Article Title #6',
  30. 'Le title d\'article numero neuf',
  31. 'Another quite long Article Title (but not the longest)',
  32. 'This is possibly the longest of all of the Article Titles that I can possibly write'
  33.  
  34. );
  35. $classes = 'grid-item';
  36. switch ($i % 3) {
  37. case 0:
  38. $classes .= ' tall';
  39. break;
  40. case 1:
  41. $classes .= ' wide';
  42. break;
  43. case 2:
  44. $classes .= ' small';
  45. break;
  46. }
  47. if ($i == 0) {
  48. $classes .= ' large';
  49. }
  50. ?>
  51. <article class="<?php echo $classes; ?>">
  52. <?php if ($i >= 9) {
  53. $col = ($i - 1);
  54. } else {
  55. $col = $i;
  56. }
  57.  
  58. if (strlen($title[$i]) >= 35) {
  59. $fz = "16px";
  60. } else {
  61. $fz = "27px";
  62. }
  63.  
  64. ?>
  65. <div id="article-<?php echo $i; ?>" class="content" style="background: linear-gradient(#<?php echo $col; ?><?php echo $col; ?>0000, #<?php echo $col; ?><?php echo $col; ?>0055)">
  66. <h2 style="font-size: <?php echo $fz; ?>;">
  67. <?php echo $title[$i]; ?>
  68. </h2>
  69. </div>
  70. </article>
  71. <?php }
  72. ?>
  73. </section>
  74. <script>
  75. function masonry() {
  76. $('#gradient-wrapper').masonry({
  77. // options
  78. itemSelector: '.grid-item',
  79. columnWidth: 200
  80. });
  81. }
  82. $(document).ready(function () {
  83. masonry();
  84. });
  85. </script>
  86. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement