UX: onebox images no longer cause jiggle
This stops pages from "jiggling" while oneboxes download. see: http://cssmojo.com/aspect-ratio-using-custom-properties-and-calc/
This commit is contained in:
parent
7c5a71e929
commit
9197feefb8
|
@ -140,6 +140,50 @@ aside.onebox {
|
|||
margin-right: 10px;
|
||||
}
|
||||
|
||||
[style*="--aspect-ratio"] > :first-child {
|
||||
width: 100%;
|
||||
}
|
||||
[style*="--aspect-ratio"] > img {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
// this allows us to load all onebox images without jiggle
|
||||
// see: http://cssmojo.com/aspect-ratio-using-custom-properties-and-calc/
|
||||
@supports (--custom:property) {
|
||||
|
||||
.aspect-image {
|
||||
max-height: 170px;
|
||||
max-width: 20%;
|
||||
float: left;
|
||||
margin-right: 10px;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: inherit;
|
||||
max-width: initial;
|
||||
max-height: initial;
|
||||
float: none;
|
||||
margin-right: none;
|
||||
}
|
||||
}
|
||||
[style*="--aspect-ratio"] {
|
||||
position: relative;
|
||||
}
|
||||
[style*="--aspect-ratio"]::before {
|
||||
content: "";
|
||||
display: block;
|
||||
padding-bottom: calc(100% / (var(--aspect-ratio)));
|
||||
}
|
||||
[style*="--aspect-ratio"] > :first-child {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
// tighten bottom margin on last para
|
||||
p:last-child {
|
||||
margin-bottom: 4px;
|
||||
|
|
|
@ -323,7 +323,16 @@ class CookedPostProcessor
|
|||
end
|
||||
|
||||
# make sure we grab dimensions for oneboxed images
|
||||
oneboxed_images.each { |img| limit_size!(img) }
|
||||
# and wrap in a div
|
||||
oneboxed_images.each do |img|
|
||||
limit_size!(img)
|
||||
if (width = img["width"].to_i) > 0 && (height = img["height"].to_i) > 0
|
||||
img.delete('width')
|
||||
img.delete('height')
|
||||
new_parent = img.add_next_sibling("<div class='aspect-image' style='--aspect-ratio:#{width}/#{height};'/>")
|
||||
new_parent.first.add_child(img)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def optimize_urls
|
||||
|
|
Loading…
Reference in New Issue