[Blogger] Display Posts in Grid View with Thumbnails



  1. <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  2. <script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>
  3. <b:if cond='data:blog.pageType == &quot;index&quot;'>
  4. <script type='text/javascript'>//<![CDATA[
  5. $(document).ready(function() {
  6. var width = 200;
  7. var height = 170;
  8. var placeholder = 'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5fYRn5tkKKc9q6XrCWMcd2685kUXA8YEElw73J2fY9nReW315WWjMb8WF7ui3vXNjKHc969EnkT8mzUjlTbCwmu8jVgvhAlXnbU7z-skXSWTsXjDal-GMt6jISaG8YeSCFX5T7PT5_Ww/s1600/no-thumb.png';
  9. var margins = "0px 0px 10px 10px";
  10. var fitThumb = 1;
  11. var titleTopPadding = 5;
  12. var titleBottomPadding = 8;
  13. var titleLeftRightPadding = 5;
  14. var titlePadding = titleTopPadding + 'px ' + titleLeftRightPadding + 'px ' + titleBottomPadding + 'px ' + titleLeftRightPadding + 'px';
  15. $('.post-body').each(function(n, wrapper) {
  16. var wrapper = $(wrapper);
  17. var image = $(wrapper).find('img').first();
  18. var link = wrapper.parent().find('h3 a');
  19. var linkURL = link.attr('href');
  20. var linkTitle = link.text();
  21. $(link).remove();
  22. wrapper.empty();
  23. if (image.attr('src')) {
  24. var thumbHeight = image.attr('height');
  25. var thumbWidth = image.attr('width');
  26. var thumbParent = $(image).parent();
  27. wrapper.append(thumbParent);
  28. if (fitThumb) {
  29. image.attr({
  30. src: image.attr('src').replace(/s\B\d{3,4}/, 's' + width + '-c')
  31. });
  32. image.attr('width', width).attr('height', height);
  33. } else {
  34. image.attr({
  35. src: image.attr('src').replace(/s\B\d{3,4}/, 's' + width)
  36. });
  37. image.attr('width', width);
  38. var changeHeight = (thumbHeight / thumbWidth * width).toFixed(0);
  39. image.attr('height', changeHeight);
  40. }
  41. } else {
  42. var image = $('<img>').attr('src', placeholder).attr('height', height).attr('width', width);
  43. var thumbParent = $('<a>').append(image).appendTo(wrapper);
  44. }
  45. thumbParent.attr('href', linkURL).css('clear', 'none').css('margin-left', '0').css('margin-right', '0').addClass('postThumbnail');
  46. var thumbTitle = $('<div>').prepend(linkTitle).css('padding', titlePadding).css('opacity', '0.9').css('filter', 'alpha(opacity=0.9)').css('width', width).appendTo(thumbParent);
  47. var ptitleHeight = thumbTitle.height();
  48. var summary = parseInt(ptitleHeight) + parseInt(titleTopPadding) + parseInt(titleBottomPadding);
  49. thumbTitle.css('margin-top', '-' + summary + 'px');
  50. wrapper.css('float', 'left').css('height', height).css('width', width).css('margin', margins).css('overflow', 'hidden');
  51. });
  52. $('#blog-pager').css('clear', 'both');
  53. });
  54. function hideLightbox() {
  55. var images = document.getElementsByTagName('img');
  56. for (var i = 0; i < images.length;++i) {
  57. images[i].onmouseover = function() {
  58. var html = this.parentNode.innerHTML;
  59. this.parentNode.innerHTML = html;
  60. this.onmouseover = null;
  61. };
  62. }
  63. }
  64. if (window.addEventListener) {
  65. window.addEventListener('load', hideLightbox, undefined);
  66. } else {
  67. window.attachEvent('onload', hideLightbox);
  68. }
  69. //]]>
  70. </script>
  71. <style>
  72. .post {
  73. border-bottom: 0 dotted #E6E6E6;
  74. margin-bottom: 0;
  75. padding-bottom: 0;
  76. }
  77. h2,.post-footer {
  78. display: none;
  79. }
  80. a.postThumbnail div {
  81. text-decoration: none;
  82. color: #fff;
  83. font-size: 12px;
  84. font-weight: bold;
  85. text-transform: capitalize;
  86. background: rgb(125,126,125);
  87. /* Old browsers */
  88. background: -moz-linear-gradient(top, rgba(125,126,125,1) 0%, rgba(14,14,14,1) 100%);
  89. background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(125,126,125,1)), color-stop(100%,rgba(14,14,14,1)));
  90. /* Chrome,Safari4+ */
  91. background: -webkit-linear-gradient(top, rgba(125,126,125,1) 0%,rgba(14,14,14,1) 100%);
  92. background: -o-linear-gradient(top, rgba(125,126,125,1) 0%,rgba(14,14,14,1) 100%);
  93. background: -ms-linear-gradient(top, rgba(125,126,125,1) 0%,rgba(14,14,14,1) 100%);
  94. background: linear-gradient(to bottom, rgba(125,126,125,1) 0%,rgba(14,14,14,1) 100%);
  95. filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=&#39;
  96. #7d7e7d&#39;, endColorstr=&#39;#0e0e0e&#39;,GradientType=0 );
  97. }
  98. a.postThumbnail:hover div {
  99. display: block;
  100. }
  101. .post-body img {
  102. background-color: transparent;
  103. border: 1px solid transparent;
  104. padding: 0px;
  105. -webkit-border-radius: 12px;
  106. -moz-border-radius: 12px;
  107. border-radius: 12px;
  108. opacity: 1;
  109. transition: opacity .25s ease-in-out;
  110. -moz-transition: opacity .25s ease-in-out;
  111. -webkit-transition: opacity .25s ease-in-out;
  112. }
  113. .post-body img:hover {
  114. -ms-filter: &quot;
  115. progid: DXImageTransform.Microsoft.Alpha(Opacity=70)&quot;
  116. ;
  117. filter: alpha(opacity=70);
  118. -moz-opacity: 0.7;
  119. -khtml-opacity: 0.7;
  120. opacity: 0.7;
  121. }
  122. </style>
  123. </b:if>

超棒!程式碼編排器  http://hilite.me

Source

Display Blogger Posts in Grid View with Thumbnails

沒有留言:

技術提供:Blogger.