pusatdata

Script Otomatis Full Width Image in Blogspot

Sep 13th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. letakkan di dalam head:
  2.  
  3. <script language='javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'/>
  4. <script type='text/javascript'>
  5. //<![CDATA[
  6. $(document).ready(function() {
  7. $.fn.resizeImage = function() {
  8. $('.post-body').table_to_div();
  9. var postWidth = $('.post-body').width();
  10. var sAttribut = /\/s\B\d{2,4}/;
  11.  
  12. $('.post-body').find('img').each(function(n, image){
  13. var thisHeight = $(this).height();
  14. var thisWidth = $(this).width();
  15. var thisRatio = thisWidth / thisHeight;
  16. var newWidth = postWidth;
  17. var newHeight = Math.round(newWidth / thisRatio);
  18. var newDimension;
  19. if(thisWidth >= thisHeight) {
  20. newDimension = newWidth
  21. }
  22. else {
  23. newDimension = newHeight
  24. };
  25. var image = $(image);
  26. image.removeAttr("width height");
  27. image.css({
  28. "margin-left": "0",
  29. "padding":"0",
  30. "box-sizing": "border-box",
  31. "box-shadow": "0 0 0 rgba(0, 0, 0, 0)",
  32. "width": newWidth + "px",
  33. });
  34. image.parent().removeAttr("style");
  35. image.attr({src : image.attr('src').replace( sAttribut,'/' + 's' + newDimension )});
  36. image.attr('width',newWidth);
  37. });
  38. };
  39. $.fn.table_to_div = function() {
  40. $(this).find('table').each(function(){
  41. $(this).find('a').unwrap().unwrap();
  42. $(this).find('.tr-caption').unwrap();
  43. $(this).replaceWith( $('table').html()
  44. .replace(/<tbody/gi, "<div class='separator' style='clear: both; text-align: center'")
  45. .replace(/<tr/gi, "<div style='text-align: center'")
  46. .replace(/<\/tr>/gi, "</div>")
  47. .replace(/<td/gi, "<div")
  48. .replace(/<\/td>/gi, "</div>")
  49. .replace(/<\/tbody/gi, "<\/div")
  50. );
  51. });
  52. };
  53. $('body').resizeImage();
  54. $(window).resize(function() {
  55. $('body').resizeImage();
  56. });
  57. });
  58. //]]>
  59. </script>
  60.  
  61. ===========
  62. jika file ini <script language='javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'/>
  63. sudah ada, maka yg ini tidak perlu dipasang, cukup pasang script yg dibahanya.
  64.  
Add Comment
Please, Sign In to add comment