Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image aspect ratio to placeholders #54

Open
wants to merge 2 commits into
base: pThumb-dev
Choose a base branch
from

Conversation

davidpede
Copy link

@davidpede davidpede commented Apr 12, 2018

Very helpful when using CSS solutions like: https://css-tricks.com/aspect-ratio-boxes/ to size dynamic width image containers and (or) lazy loading images. Example:

<html>
  <head>
    <style>
      .lazy-container {
        background-color: #C5C7C8;
        display: block;
        position: relative;
        height: 0;
        padding-top: 55.3%; //default
      }
      .lazy-container img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
      }
    </style>
  </head>
  <body>
    [[pthumb? &input=`[[*image]]` &options=`w=200` &toPlaceholder=`thumb`]]
    <div class="column" style="width: 20%;"> //can be any width
      <a href="#" class="lazy-container" style="padding-top: [[+thumb.ratio]]%;">
        <img class="lazy" data-src="[[+thumb]]"> //remove 'data-' to view image
      </a>
    </div>
  </body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant