Mirror image but keep translate stable - css

When I flipped the image, also transform: translate in goes the reverse direction.
How to achieve a mirror image in the current translated position?
img {
transform: translate(50px, 100px);
/* scale:-1; */
}
<img class="draggable" src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634__340.png" width=200>
Since image is dragging with a function and updated transform dynamicaly expecting to find different than this solution -> transform: translate(50px, 100px) scale(-1);

You don't really need transform-property anymore, as far as I know, you could just do:
img {
translate: 50px 100px;
scale: -1 1;
}
<img class="draggable" src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634__340.png" width=200>
The scale-property takes up to 3 values, corresponding to the 3 axis (x,y,z).
If only 1 value is provided it takes that for both x- and y-axis. That's why you can give it to values, first one for the x-axis, second one for the y-axis.

solved by wrapping scaled element with another div
img {
scale: -1 1;
}
.img-wrapper{
transform: translate(50px, 100px);
}
<div class="img-wrapper draggable">
<img class="" src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634__340.png" width=200>
</div>

Having the translate properties calculated separately seems to do the trick
img{
transform: translateX(50px) translateY(100px) scaleX(-1);
}
<img class="draggable" src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634__340.png" width=200>

Related

Translate function not changing the position of a button in React

I'm trying to change the position of a button on my React page, but the transform: translate function is not working. I've tried changing the position to absolute, static, fixed, but nothing moves the button.
CSS:
position: absolute;
transform: translate(-600x, 300x);
}
TSX:
<div className="Transform">
<button onClick={clickHandler}>
<img src="https://i.ibb.co/zf3vqPf/imageedit-4-2431153664.png" alt = "Button_image" />
</button>
</div>
Other CSS is working, but translate is not.
transform: translate(-600x, 300x);
Use px , em , rem etc as X is not a unit
transform: translate(-600px , 300px);

Vue2: v-move not applied to "leave" transition

Goal —
Smoothly animate a changing list of items.
Problem —
When an item enters the list, everything repositions smoothly. When an item leaves the list, everything snaps abruptly.
I've discovered that .drawer-move is applied when new items enter, but .drawer-move is not applied when items leave.
Docs: https://v2.vuejs.org/v2/guide/transitions.html#List-Move-Transitions
Template —
<transition-group class="utilities -animate" tag="section" name="drawer">
<div class="drawer" key="application-drawer">
<div class="heading">Select An Application</div>
</div>
<div class="drawer" v-if="selectCompanyVisible" key="company-drawer">
<div class="heading">Select A Company</div>
</div>
<div class="drawer" key="manage-drawer">
<div class="heading">Manage {{ user.id }}</div>
</div>
</transition-group>
CSS —
.drawer-enter-active,
.drawer-leave-active,
.drawer-move {
transition-property: opacity, transform;
transition-timing-function: cubic-bezier(0.5, 0, 0.5, 1);
transition-duration: .4s;
}
.drawer-enter,
.drawer-leave-to {
opacity: 0;
transform: translateX(3rem);
}
The -leave-active transition class must apply a position: absolute declaration, in order to take it out of the layout flow, so the siblings can move in to place around it.
https://forum.vuejs.org/t/transition-group-move-class-not-occuring-in-the-array/6381/4
This also could mean that you should declare positioning within the transition-group element. No one mentions this in the Vue team, but I don't find this applied automatically by the transition classes.
.drawer-leave-active {
position: absolute;
// optional, depends on your layout
left: 0;
width: 100%;
}
.utilities {
position: relative;
}

Seamless SVG Loop

Hi iv been trying to do some animations for a project in my web development class. I am trying to create the illusion that a car in moving on a street by having the street and some mountains moving horizontally on an endless loop but I also need the photo to repeat. I found how to do this with {background-position} but I can't get the photo to seamlessly scroll without there being a gap any suggestions?
body {
background-color: rgb(59, 193, 236);
}
#Mountains {
transform: translate(-8px, -400px);
animation: slide 2s linear infinite;
}
#keyframes slide {
from {
transform: translate(-8px, -400px);
}
to {
transform: translate(1109px, -400px);
}
}
<div id="Mountains">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1109" height="1500" viewBox="0 0 2100 1500">
<metadata><?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.6-c138 79.159824, 2016/09/14-01:09:01 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""/>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?></metadata>
<image y="316" width="2100" height="1184" xlink:href="data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAACDQAAASgCAMAAAA63XraAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAC+lBMVEVirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAdirAcAAABEFMKVAAAA/HRSTlMADh4tPExba3iIkpmaqrO7x8zZ3d/u3MGjh04sBjJlja7Q8vvYrIRZMQk3apvN+vzbsV4qAhWg0/G9hlAaNX7K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iAYAICIaAICIaAAAIqIBAIiIBgAgIhoAgIhoAAAiogEAiIgGACAiGgCAiGgAACKiAQCIiAYAICIaAICIaAAAIqIBAIiIBgAgIhoAgIhoAAAiogEAiIgGACAiGgCAiGgAACKiAQCIiAYAICIaAICIaAAAIqIBAIiIBgAgIhoAgIhoAAAiogEAiIgGACAiGgCAiGgAACKiAQCIiAYAICIaAICIaAAAIqIBAIiIBgAgIhoAgIhoAAAiogEAiIgGACAiGgCAiGgAACKiAQCIiAYAICIaAICIaAAAIqIBAIiIBgAgIhoAgIhoAAAiogEAiIgGACAiGgCAiGgAACKiAQCIiAYAICIaAICIaAAAIqIBAIiIBgAgIhoAgIhoAAAiogEAiIgGACAiGgCAiGgAACKiAQCIiAYAICIaAICIaAAAIqIBAIiIBgAgIhoAgIhoAAAiogEAiIgGACAiGgCAiGgAACKiAQCIiAYAICIaAICIaAAAIqIBAIiIBgAgIhoAgIhoAAAiogEAiIgGACAiGgCAyP8H5b63vEwYaTcAAAAASUVORK5CYII="/>
</svg>
</div>
I haven't though of a solution with only one SVG. But if you can wrap two images (not necessarily the same) in a container, it is easy to make a repeating animation using the animation-delay property for the second image.
See the example:
https://jsfiddle.net/kxo7g714/
.mountains {
position: absolute;
top: 0;
left: 0;
transform: translate(-150px, 50px);
animation: slide 4s linear infinite;
}
.mountains.two {
animation-delay: -2s;
}
If you can use only one image, duplicate it's content inside of the image itself. The example uses different colors to illustrate how the paths are essentially the same.
https://jsfiddle.net/crvpenfo/2/
#keyframes slide {
from {
transform: translate(0, 50px);
}
to {
transform: translate( "NegativeHalfWidth" , 50px);
}
}

Angular Material: Md-sidenav-right with md-tabs not working in IE

Note: This problem can only be seen in IE 11 down. IE Edge (including emulation) will not show the issue.
I'm having a crazy problem when I combined md-tabs with md-sidenav. Here is the plunkr:
http://embed.plnkr.co/if7VqrZoFKBJt4lAAoy0/
<md-sidenav class="md-sidenav-right md-whiteframe-z2" md-component-id="right">
<md-toolbar class="md-theme-light">
<h1 class="md-toolbar-tools">Sidenav Right</h1>
</md-toolbar>
<md-content layout-padding="">
<md-tabs>
<md-tab label="Tab #1"></md-tab>
<md-tab label="Tab #2"></md-tab>
<md-tab label="Tab #3"></md-tab>
</md-tabs>
</md-content>
</md-sidenav>
I've duplicated 2 sidenavs: one uses the classmd-sidenav-left and the other uses md-sidenav-right. The right one does not allow for the tabs or any content to be interacted with.
The example and my actual code are using 0.11.4 but I've also tested 1.0 and it has the same issue.
Has anyone run into this issue? The example on the Materials site works just fine but it does not use tabs. I'm thinking it's a translate3d css issue but can't confirm it.
Turns out their css was trying to piggyback on md-sidenav-left instead of creating a new style.
Here is the fixed Plunker:
http://embed.plnkr.co/7L6GuUH036F2W9i7JPwl/
Here is the original SCSS from the build:
.md-sidenav-right {
left: 100%;
top: 0;
transform: translate3d(-100%, 0, 0);
&.md-closed {
transform: translate3d(0%, 0, 0);
}
}
translate3d and left: 100% turned out to be the issue. The reason why it exists though is to create the correct animation.
Here is the corrected SCSS:
.md-sidenav-right {
left: inherit;
right: 0;
transform: translate3d(0,0,0);
&.md-closed {
transform: translate3d(100%,0,0);
}
}

Placeholder background/image while waiting for full image to load?

I have a few images on my page. I'm finding that the page starts to render before the images have been loading (which is good), but that the visual effect is not great. Initially the user sees this:
--------hr--------
text
Then a few milliseconds later the page jumps to show this:
--------hr--------
[ ]
[ image ]
[ ]
text
Is there a simple way that I can show a grey background image of exactly the width and height that the image will occupy, until the image itself loads?
The complicating factor is that I don't know the height and width of the images in advance: they are responsive, and just set to width: 100% of the containing div. This is the HTML/CSS:
<div class="thumbnail">
<img src="myimage.jpeg" />
<div class="caption">caption</div>
</div>
img { width: 100% }
Here's a JSFiddle to illustrate the basic problem: http://jsfiddle.net/X8rTB/3/
I've looked into things like LazyLoad, but I can't help feeling there must be a simpler, non-JS answer. Or is the fact that I don't know the height of the image in advance an insurmountable problem? I do know the aspect ratio of the images.
Instead of referencing the image directly, stick it within a DIV, like the following:
<div class="placeholder">
<div class="myimage" style="background-image: url({somedynamicimageurl})"><img /></div>
</div>
Then in your CSS:
.placeholder {
width: 300;
height: 300;
background-repeat: no-repeat;
background-size: contain;
background-image: url('my_placeholder.png');
}
Keep in mind - the previous answers that recommend using a div background approach will change the semantic of your image by turning it from an img into a div background. This will result in things like no indexing of these images by a search crawler, delay in loading of these images by the browser (unless you explicitly preload them), etc.
A solution to this issue (while not using the div background approach) is to have a wrapper div to your image and add padding-top to it based on the aspect ratio of the image that you need to know in advance. The below code will work for an image with an aspect ratio of 2:1 (height is 50% of width).
<div style="width:100%;height:0; padding-top:50%;position:relative;">
<img src="<imgUrl>" style="position:absolute; top:0; left:0; width:100%;">
</div>
Of course - the major disadvantage of this approach is that you need to know the aspect ratio of the image in advance.
There is a really simple thing to check before you start looking into lazy-loading and other JavaScript. Make sure the JPEG images you are loading are saved with the 'progressive' option enabled!
This will cause them to load the image iteratively, starting with a placeholder that is low-resolution and faster to download, rather than waiting for the highest resolution data before rendering.
It's very simple...
This scenario allows to load a profile photo that defaults to a placeholder image.
You could load multi CSS background-image into an element. When an avatar photo fails, the placeholder image appears default of div.
If you're using a div element that loads via a CSS background-image, you could use this style:
#avatarImage {
background-image: url("place-holder-image.png"), url("avatar-image.png");
}
<div id="avatarImage"></div>
Feel free to copy this:
<script>
window.addEventListener("load", function () {
document.getElementById('image').style.backgroundColor = 'transparent';
});
</script>
<body>
<image src="example.example.example" alt="example" id="image" style="background-color:blue;">
</body>
I got this from here: Preloader keeps on loading and doesnt disappear when the content is loaded.
Apart from all solutions already mentioned, the last solution would be to hide the document until everything is loaded.
window.addEventListener('load', (e) => {
document.body.classList.add('loaded');
});
body {
opacity: 0;
}
body.loaded {
opacity: 1;
}
<div id="sidebar">
<img src="http://farm9.staticflickr.com/8075/8449869813_1e62a60f01_b.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-1.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-2.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-3.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-4.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-5.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-6.jpg" />
</div>
Or show some animation while everything is loading:
window.addEventListener('load', (e) => {
document.body.classList.add('loaded');
});
.loader {
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 70px;
height: 70px;
-webkit-animation: spin 2s linear infinite;
/* Safari */
animation: spin 2s linear infinite;
position: absolute;
left: calc(50% - 35px);
top: calc(50% - 35px);
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
body :not(.loader) {
opacity: 0;
}
body .loader {
display: block;
}
body.loaded :not(.loader) {
opacity: 1;
}
body.loaded .loader {
display: none;
}
<div class="loader"></div>
<div id="sidebar">
<img src="http://farm9.staticflickr.com/8075/8449869813_1e62a60f01_b.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-1.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-2.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-3.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-4.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-5.jpg" />
<img src="https://www.nla.gov.au/sites/default/files/pic-6.jpg" />
</div>
The only thing I can think of, to minimize the jump effect on your text, is to set min-height to where the image will appear, I would say - set it to the "shorter" image you know of. This way the jump will be less evident and you won't need to use lazyLoad or so... However it doesn't completely fix your problem.
Here's one naive way of doing it,
img {
box-shadow: 0 0 10px 0 rgba(#000, 0.1);
}
You can manipulate the values, but it creates a very light border around the image that doesn't push the contents. Images can load at whatever time they want, and you get a good user experience.
Here is what I did with Tailwind CSS, but it's just CSS:
img {
#apply bg-no-repeat bg-center;
body.locale-en & {
background-image: url("data:image/svg+xml;utf8,<svg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'><text x='50%' y='50%' style='font-family: sans-serif; font-size: 12px;' dominant-baseline='middle' text-anchor='middle'>Loading…</text></svg>");
}
body.locale-fr & {
background-image: url("data:image/svg+xml;utf8,<svg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'><text x='50%' y='50%' style='font-family: sans-serif; font-size: 12px;' dominant-baseline='middle' text-anchor='middle'>Chargement…</text></svg>");
}
}
You can find the width and height of the images in the developer tools console, for example in Chrome you can click the cursor icon in the developer tools console and when you hover on the page it will highlight all the properties of the elements in the page.
This will help you find the width and height of the images, because if you hover on top of your images it will give you the dimensions of the image and other more properties. You can also make an individual div for each image and make the div relative to the images width and height. You can do it like this:
The main div will contain the images and also the background-div which is below the image.
HTML:
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div class=".mainDiv">
<div class="below"></div>
<img src="https://imgix.bustle.com/uploads/image/2020/2/13/da1a1ca4-95ec-40ea-83c1-4f07fac8b9b7-eqb9xdwx0auhotc.jpg" width="500"/>
</div>
</body>
</html>
CSS:
.mainDiv {
position: relative;
}
.below {
position: absolute;
background: #96a0aa;
width: 500px;
height: 281px;
}
img {
position: absolute;
}
The result will be that .below will be below the image and so when the image has trouble loading the user will instead see the grey .below div. You cannot see the .below div because it is hidden below the image. The only time you will see this is when the loading of the image is delayed. And this will solve all your problems.
I have got a way. But you will need to use JavaScript for it.
The HTML:
img = document.getElementById("img")
text = document.getElementById("text")
document.addEventListener("DOMContentLoaded", () => {
img.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAA1BMVEWIiIhYZW6zAAAASElEQVR4nO3BgQAAAADDoPlTX+AIVQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwDcaiAAFXD1ujAAAAAElFTkSuQmCC";
text.innerHTML = "Loaded but image is not";
});
window.onload = function() {
img.src = "https://media.geeksforgeeks.org/wp-content/uploads/20190913002133/body-onload-console.png";
text.innerHTML = "Image is now loaded";
};
#img {
width: 400px;
height: 300px;
}
<hr>
<img id="img" src="https://media.geeksforgeeks.org/wp-content/uploads/20190913002133/body-onload-console.png">
<p>Here is the Image</p>
<p id="text">Not Loaded</p>

Resources