add transition effect in vue on backgroundImage - css

I've been searching for a couple of days to add a fade transition effect on the backgroundImage that I'm changing through a Vue app.
Here is the code snippet I've been testing on:
new Vue({
el: "#main",
data: {
images: [
"https://images.freeimages.com/images/large-previews/bfd/clouds-1371838.jpg",
"https://images.freeimages.com/images/large-previews/ffa/water-lilly-1368676.jpg",
"https://images.freeimages.com/images/large-previews/efb/lotus-flower-1382251.jpg"
],
current: 0,
show: false
},
methods: {
changeBG: function () {
if (this.current < this.images.length - 1) {
this.current = this.current + 1;
} else {
this.current = 0;
}
}
}
});
.main {
height: 800px;
width: 100%;
margin-left: auto;
margin-right: auto;
z-index: 0;
background-repeat: no-repeat;
background-size: cover;
background-position: center 0px;
}
button {
width: 200px;
height: 25px;
margin: 10px;
}
p.hello{
color: white;
margin: 10px;
font-size: 50px;
}
.fade-enter-active,
.fade-leave-active {
transition: all 2s linear;
}
.fade-enter-to,
.fade-leave {
opacity: 0;
}
.fade-enter,
.fade-leave-to {
opacity: 1;
}
/* hello example transition */
.slide-fade-enter-active {
transition: all 1s ease;
}
.slide-fade-leave-active {
transition: all 1s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
transform: translateX(10px);
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<transition name="fade">
<div v-if="changeBG" class="main" id="main" :style="{ backgroundImage: 'url(\'' + images[current] + '\')' }">
<button v-on:click="changeBG">
changeBG
</button>
<div id="testFromGuide">
<button #click="show = !show">
toggleHello
</button>
<transition name="slide-fade">
<p class="hello" v-if="show">all your base are belong to us</p>
</transition>
</div>
</div>
</transition>
My first question if this is simply possible? The reason I'm using backgroundImage is because the website I'm using this on has a background that is most easy to handle responsively through this (always covering, no repeat and keeping it center). And my scond question would be, if not, is there a possibility to make it work with a background set as described here?
In the codepen I've added an example of the vue guide to make sure it works and nothing is else is wrong. And the example works perfectly. Can't seem to find the answer for my example but I've been beginning to suspect it is simply not possible or I can't seem to find why vue isn't detecting something is changing.

For Vue Transitions to work, you need to change the DOM elements. So this way would work if you were changing actual images out. In your example, you're only changing an attribute value. The DOM doesn't trigger a transition since its the same element.
However, you can use the :key attribute to convince VUE to replace the element thus giving you a transition between 2 elements.
You can also set the image with inline CSS like you're doing in the example. You'll still have to create the transition in your CSS.
Here's an example using Vue Transition
new Vue({
el: "#main",
data: {
currentID: 0,
images: [
'https://images.freeimages.com/images/large-previews/efb/lotus-flower-1382251.jpg',
'https://images.freeimages.com/images/large-previews/ffa/water-lilly-1368676.jpg',
'https://images.freeimages.com/images/large-previews/bfd/clouds-1371838.jpg'
]
},
methods: {
toggleImage: function(){
if(this.currentID < this.images.length-1){
this.currentID +=1
} else {
this.currentID = 0
}
}
}
});
body {
overflow: hidden;
}
.main {
position: relative;
}
img {
width: 100%;
height: auto;
display: block;
position: absolute;
-webkit-transition: all 3s ease;
transition: all 3s ease;
}
button {
z-index: 100;
position: relative;
width: 200px;
height: 25px;
margin: 20px;
}
/* prefix with transition name */
.slide-fade-enter-active {
opacity: 1;
z-index: 10;
}
.slide-fade-leave-active {
opacity: 1;
}
.slide-fade-enter,
.slide-fade-leave-to {
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
<div class="main" id="main">
<transition name="slide-fade">
<!-- SRC comes from the array of images the :key is important for vue to believe its a 'new' DOM element and do the transition -->
<img v-bind:src="images[currentID]" v-bind:key="currentID" />
</transition>
<button #click="toggleImage">
Toggle Image
</button>
</div>
However, you don't get a lot of control over that since it uses image tags. Instead, it might be better to use a background image like this:
new Vue({
el: "#main",
data: {
currentID: 0,
images: [
'https://images.freeimages.com/images/large-previews/efb/lotus-flower-1382251.jpg',
'https://images.freeimages.com/images/large-previews/ffa/water-lilly-1368676.jpg',
'https://images.freeimages.com/images/large-previews/bfd/clouds-1371838.jpg'
]
},
methods: {
toggleImage: function(){
if(this.currentID < this.images.length-1){
this.currentID +=1
} else {
this.currentID = 0
}
}
}
});
.main {
/* make this the size of the window */
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.theImage {
width: 100%;
height: 100%;
position: absolute;
background-color: #333;
background-size: contain;
background-repeat: no-repeat;
background-position: center center;
-webkit-transition: all 3s ease;
transition: all 3s ease;
}
button {
z-index: 100;
position: relative;
width: 200px;
height: 25px;
margin: 20px;
}
/* prefix with transition name */
.slide-fade-enter-active {
opacity: 1;
z-index: 10;
}
.slide-fade-leave-active {
opacity: 1;
}
.slide-fade-enter,
.slide-fade-leave-to {
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
<div class="main" id="main">
<transition name="slide-fade">
<!-- SRC comes from the array of images the :key is important for vue to believe its a 'new' DOM element and do the transition -->
<div class="theImage" v-bind:style="{'background-image': 'url(' + images[currentID] + ')'}" v-bind:key="currentID"></div>
</transition>
<button #click="toggleImage">
Toggle Image
</button>
</div>

The answer was indeed to forget about vue transitions and let css do the work. A working example can be found here:
new Vue({
el: "#main",
data: {
show: false,
BG1: true,
BG2: false,
BG3: false
},
methods: {
changeBG: function(){
if (this.BG1 == true){
this.BG1 = false;
this.BG2 = true;
this.BG3 = false;
} else if (this.BG2 == true) {
this.BG1 = false;
this.BG2 = false;
this.BG3 = true;
} else if (this.BG3 == true) {
this.BG1 = true;
this.BG2 = false;
this.BG3 = false;
}
},
showBG1: function(){
if (this.BG1 == true){
return "";
} else {
return "transparent";
}
},
showBG2: function(){
if (this.BG2 == true){
return "";
} else {
return "transparent";
}
},
showBG3: function(){
if (this.BG3 == true){
return "";
} else {
return "transparent";
}
}
}
});
.main {
}
#bgs img.transparent {
opacity:0;
transform: translateY(-0.0px);
}
#bgs img{
/* Set rules to fill background */
min-height: 100%;
min-width: 1024px;
/* Set up proportionate scaling */
width: 100%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0;
left: 0;
z-index: -1;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
}
#media screen and (max-width: 1024px) { /* Specific to this particular image */
#bgs img{
left: 50%;
margin-left: -512px; /* 50% */
}
}
button {
z-index: 100;
position: relative;
width: 200px;
height: 25px;
margin: 20px;
}
p.hello{
color: white;
margin: 40px;
font-size: 50px;
}
.fade-enter-active {
transition: all 1s ease;
}
.fade-leave-active {
transition: all 1s ease;
}
.fade-enter, .fade-leave-to{
transform: translateY(-5px);
opacity: 0;
}
/* hello example transition */
.slide-fade-enter-active {
transition: all 1s ease;
}
.slide-fade-leave-active {
transition: all 1s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter,
.slide-fade-leave-to {
transform: translateY(-5px);
opacity: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
<div class="main" id="main">
<div id="bgs">
<img :class="showBG1()" src="https://images.freeimages.com/images/large-previews/efb/lotus-flower-1382251.jpg">
<img :class="showBG2()" src="https://images.freeimages.com/images/large-previews/ffa/water-lilly-1368676.jpg">
<img :class="showBG3()" src="https://images.freeimages.com/images/large-previews/bfd/clouds-1371838.jpg">
</div>
<button #click="changeBG">
changeBG
</button>
<div id="testFromGuide">
<button #click="show = !show">
toggleHello
</button>
<transition name="slide-fade">
<p class="hello" v-if="show">all your base are belong to us</p>
</transition>
</div>
</div>
It's not perfect yet as for every extra background I need to add a function and add an extra if else loop to the changeBG function. It would be more elegant if this could be done with a list variable but I've not found a way to make this work with the :class method. I hope to look into this at a later time.

Related

Why wont animation reset and play again after class is added dynamically to the element for the second time

this code changes the background of the div every time a button is pressed but the new background is supposed to fade in so I set an animation. If you press red, and then another color, it makes the transition the first time, but not from the second on. The background will just appear without animation.
function changit(color) {
document.getElementById('cont').classList = color;
}
#keyframes appear {
0% {opacity:0;}
100% {opacity:1;}
}
#cont {
position: relative;
width: 100px;
height: 100px;
display: block;
}
#cont::before {
width: 93%;
height: 100%;
position: sticky;
content: "";
display: block;
}
.red::before, .blue::before, .black::before { transition: opacity 2s ease;animation:appear 2s; }
.red::before {
background: url(https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg) no-repeat;
}
.blue::before {
background: url(https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=64&d=identicon&r=PG) no-repeat;
}
.black::before {
background:url(https://cdn.sstatic.net/Sites/stackoverflow/Img/subcommunities/intel.svg?v=0371bf2f3b96) no-repeat;
}
<div id="cont">
</div>
<button onclick="changit('red');">make red</button>
<button onclick="changit('blue');">make blue</button>
<button onclick="changit('black');">make black</button>
isnt the animation supposed to play again if the element changes class? How can I reset the animation to start again every time the element changes class to achieve this effect?
The animation property value actually never changes, with all the classes it's always the same and there is no point in time where it's unset, so it won't fire again.
You need to force the CSS engine sees that it did change. For this you can remove the class altogether force what is called a "reflow", which is when the CSS engine recalculates all the element's boxes in the page, and then only, set the class back:
function changit(color) {
const elem = document.getElementById('cont');
elem.classList = "";
elem.offsetWidth; // force reflow
elem.classList = color;
}
function changit(color) {
const elem = document.getElementById('cont');
elem.classList = "";
elem.offsetWidth; // force reflow
elem.classList = color;
}
#keyframes appear {
0% {opacity:0;}
100% {opacity:1;}
}
#cont {
position: relative;
width: 100px;
height: 100px;
display: block;
}
#cont::before {
width: 93%;
height: 100%;
position: sticky;
content: "";
display: block;
}
.red::before, .blue::before, .black::before { transition: opacity 2s ease;animation:appear 2s; }
.red::before {
background: url(https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg) no-repeat;
}
.blue::before {
background: url(https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=64&d=identicon&r=PG) no-repeat;
}
.black::before {
background:url(https://cdn.sstatic.net/Sites/stackoverflow/Img/subcommunities/intel.svg?v=0371bf2f3b96) no-repeat;
}
<div id="cont">
</div>
<button onclick="changit('red');">make red</button>
<button onclick="changit('blue');">make blue</button>
<button onclick="changit('black');">make black</button>
Or, since you're using JS anyway, use the WebAnimations API:
function changit(color) {
const elem = document.getElementById('cont');
elem.classList = color;
elem.animate(
[ { opacity: 0 }, { opacity: 1 } ],
{ duration: 2000, repeat: 1 }
);
}
function changit(color) {
const elem = document.getElementById('cont');
elem.classList = color;
elem.animate(
[ { opacity: 0 }, { opacity: 1 } ],
{ duration: 2000, repeat: 1 }
);
}
#cont {
position: relative;
width: 100px;
height: 100px;
display: block;
}
#cont::before {
width: 93%;
height: 100%;
position: sticky;
content: "";
display: block;
}
.red::before {
background: url(https://cdn.sstatic.net/Img/teams/teams-illo-free-sidebar-promo.svg) no-repeat;
}
.blue::before {
background: url(https://www.gravatar.com/avatar/24780fb6df85a943c7aea0402c843737?s=64&d=identicon&r=PG) no-repeat;
}
.black::before {
background:url(https://cdn.sstatic.net/Sites/stackoverflow/Img/subcommunities/intel.svg?v=0371bf2f3b96) no-repeat;
}
<div id="cont">
</div>
<button onclick="changit('red');">make red</button>
<button onclick="changit('blue');">make blue</button>
<button onclick="changit('black');">make black</button>

How to make an animation trigger each time the page is scrolled?

I have a very sublet keyframe animation. I'd like for it to play every single time the page has been scrolled - not just once when coming in the viewpoint. Each time the scroll is touched. All I can find is running once in viewport - which is fine, but it needs to play every time the scroll is touched in the viewport. Any ideas?
/* CSS */
.aha-section .pixels .light {
margin-top: 4px;
margin-left: 33px;
animation: slide 2s 1;
}
#keyframes slide {
from {
margin-left: 33px;
}
50% {
margin-left: 45px;
}
to {
margin-left: 33px;
}
}
You will need to use some JavaScript... then you will listen to the scroll event to do the desired function...
To trigger a animation set a class to it:
.scrolled .aha-section .pixels .light {
animation: slide 2s 1;
}
and let the javascript add this class when the event scroll happens:
document.body.className += ' scrolled';
hope it helps to show you the direction.
let animated = false;
window.addEventListener("scroll", (event) => {
animateOnScroll();
});
function animateOnScroll(){
if(animated == false){
animated = !animated;
document.body.className += ' scrolled';
setTimeout(function() {
animated = false;
document.body.classList.remove('scrolled');
}, 2000); //match whatever time set on css animation
}
}
.aha-section {
position: fixed;
}
.aha-section .pixels .light {
margin-top: 4px;
margin-left: 33px;
}
.scrolled .aha-section .pixels .light {
animation: slide 2s 1;
}
#keyframes slide {
from {
margin-left: 33px;
}
50% {
margin-left: 45px;
}
to {
margin-left: 33px;
}
}
.scroll-emulator {
height: 2500px;
}
<div class="aha-section">
<div class="pixels">
<div class="light">Light</div>
</div>
</div>
<div class="scroll-emulator"><div>

UI Alignment Issue

Hope after so many tries I will get some pointers over here for issue i am facing.
As per above image, I need to have an POI in center of page(round circle in the image) and when I click on POI; I would like to open a pop up window in four position at shown in the image above with different css classes. Problem is that popup height can not be fixed and should be auto and that is where its tricky to handle the margin if I would like to achieve above UI.
Issues:
any pointers on positioning the popup with css classes as per images shown.
I have setup a fiddle here including popup and POI.
HTML:
<div id="follow-hotspot" class="hotspot-wrapper">
<img width="20px" heigh="20px" class="hotspot" src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-ios7-contact-512.png"/>
<div id="follow-textbox" class="textbox_hotspot hide" data-video="true">
<h1>Header</h1>
<p>
<b>Follow me</b> to see the css video
</p>
<iframe id="follow_video" width="230" height="150" src="https://www.youtube.com/embed/9YffrCViTVk" frameborder="0" id = "Overlayvideo" allow="accelerometer; autoplay *; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
JavaScript:
Let me know if any details are required. Any pointer how to achieve is ample enough; I am not expecting you to write code for me. How would I go about the implementation is all I am expecting.
//annonymous function
var poi = document.getElementById("follow-hotspot");
var popup = document.getElementById("follow-textbox");
poi.onclick = function() {
//alert("clicked");
if (popup.classList.contains('hide')) {
popup.classList.remove('hide');
popup.classList.add('show');
}
else if (popup.classList.contains('show')) {
popup.classList.remove('show');
popup.classList.add('hide');
videoEle = document.getElementById('follow_video');
videoEle.src = videoEle.src;
}
};
CSS:
Please refer to the fiddle for css.
I used translate property to give position to these content blocks and used percentage as units.I checked the output on changing the height and width of the content and still the position remained intact.
Glimpse of the output(->its The output)
var point_er = document.getElementsByClassName('pointer')[0];
var win_dow = document.getElementsByClassName('window');
var count = 0;
point_er.onclick = function() {
if (count % 2 == 0) {
for (var i = 0; i < win_dow.length; i++) {
win_dow[i].style.height = "250px";
win_dow[i].style.width = "300px";
}
win_dow[2].style.height = "300px";
win_dow[3].style.width = "400px";
} else {
for (var i = 0; i < win_dow.length; i++) {
win_dow[i].style.height = "0px";
win_dow[i].style.width = "0px";
}
}
count++;
}
* {
margin: 0px;
padding: 0px;
}
body {
height: 2400px;
}
.main {
width: 100%;
height: 100vh;
}
.window_main {}
.window {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 0px;
height: 0px;
border: 2px solid black;
}
.window:nth-child(1) {
transform-origin: 100% 100%;
transform: translate(-105%, -105%);
transition: 0.4s;
}
.window:nth-child(2) {
transform-origin: 0 100%;
transform: translate(5%, -105%);
transition: 0.5s;
}
.window:nth-child(3) {
transform-origin: 100% 0;
transform: translate(-105%, 5%);
transition: 0.6s;
}
.window:nth-child(4) {
transform-origin: 0% 0%;
transform: translate(5%, 5%);
transition: 0.7s;
}
.pointer {
text-decoration: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
height: 50px;
width: 50px;
background-color: #8B8AFF;
cursor: pointer;
transition: 0.4s;
}
.pointer:hover {
background-color: #6D6DE8
}
<div class="main">
<div class="window">1</div>
<div class="window">2</div>
<div class="window">3</div>
<div class="window">4</div>
</div>

Direction of Slide animation in React

I am creating a carousel and there are 2 buttons Next and Previous. on clicking Next it should slide from left to right and on clicking Previous it should slide from right to left. (I don't want to use any plugin)
My React container:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { prevItem, nextItem, initItem } from '../actions/index';
import { bindActionCreators } from 'redux';
import CSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
class Carousel extends Component{
previous(){
this.props.prevItem();
}
next(){
this.props.nextItem();
}
componentDidMount(){
this.props.initItem();
}
renderItem(){
const {item} = this.props;
const webLink = `http://${item.link}`;
const transitionOptions = {
transitionName: 'slide',
transitionEnterTimeout: 1000,
transitionLeaveTimeout: 1000
};
return(
<CSSTransitionGroup {...transitionOptions}>
<div className="carousel__item" key={item.id}>
<img className="carousel__image" src={item.imageurl}/>
<div className="carousel__text">
<h3>{item.title}</h3>
<p>{item.synopsis}</p>
{item.link}
</div>
</div>
</CSSTransitionGroup>
)
}
render(){
return(
<div className="carousel">
{this.renderItem()}
<div className="carousel__prev" onClick={this.previous.bind(this)}>
<i className="fa fa-chevron-left"></i>
</div>
<div className="carousel__next" onClick={this.next.bind(this)}>
<i className="fa fa-chevron-right"></i>
</div>
</div>
)
}
}
function mapStateToProps(state){
return {item: state.item};
}
function mapDispatchToProps(dispatch){
return bindActionCreators({
initItem: initItem,
nextItem: nextItem,
prevItem: prevItem
}, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(Carousel);
Any my Style.css is:
.carousel{
width: 100%;
border: 1px solid #ccc;
margin-top: 100px;
position: relative;
}
.carousel__item{
width: 100%;
color: #fff;
position: relative;
}
.carousel__item img{
width: 100%;
background: rgba(0,0,0,.6);
}
.carousel__text{
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.carousel__text a:hover,
.carousel__text a{
color: #fff;
}
.carousel__prev{
position: absolute;
left: 0;
top: 50%;
color: #fff;
margin-left: 10px;
cursor: pointer;
font-size: 25px;
}
.carousel__next{
position: absolute;
right: 0;
top: 50%;
color: #fff;
margin-right: 10px;
cursor: pointer;
font-size: 25px;
}
.slide-enter{
transform: translate(100%);
}
.slide-enter-active{
transform: translate(0%);
transition: transform 1000ms ease-in-out;
}
.slide-leave{
transform: translate(0%);
}
.slide-leave-active{
transform: translate(-100%);
transition: transform 1000ms ease-in-out;
}
Apart from the direction, the current slide animation is not correct. when it slides the previous slide is showing below. So basically 2 slides are showing on screen on transition. Do you know how to fix this problem and also address the direction of slide?
I just worked through this problem.
In order to slide in the correct direction, you'll need to maintain some state and apply this state to your items via className. Something like this:
render () {
<CSSTransitionGroup
component={MenuWrapper}
transitionName="slide"
transitionEnterTimeout={500}
transitionLeaveTimeout={500}>
{this._renderMenu(this.props.selectedSubMenus[menuIdx], menuIdx)}
</CSSTransitionGroup>
}
_renderMenu = (menu, idx) => {
return (
<Menu key={idx} className={this.state.animationDirection} order={idx}>
content
</Menu>
)
}
Your css should look something like this (note that I'm using styled-components for a few elements):
const menuWidth = "256px";
const MenuWrapper = styled.div`
display: flex;
overflow: hidden;
max-width: ${menuWidth};
`
const Menu = styled.div`
min-width: ${menuWidth};
order: ${props => props.order};
`
.slide-enter.left {
transform: translate(-100%);
}
.slide-enter.slide-enter-active.left {
transform: translate(0%);
transition: transform 500ms ease-in-out;
}
.slide-leave.left {
transform: translate(-100%);
}
.slide-leave.slide-leave-active.left {
transform: translate(0%);
transition: transform 500ms ease-in-out;
}
.slide-enter.right {
transform: translate(0%);
}
.slide-enter.slide-enter-active.right {
transform: translate(-100%);
transition: transform 500ms ease-in-out;
}
.slide-leave.right {
transform: translate(0%);
}
.slide-leave.slide-leave-active.right {
transform: translate(-100%);
transition: transform 500ms ease-in-out;
}
Note that I used flexbox in order to fix the display problem (as well as some hard-coded widths)
Hope this helps
We can create slide animation in the following way using slide for Dialog
const Transition = React.forwardRef(function Transition(props, ref) {
return <Slide direction='up' ref={ref} {...props} />
})
<Dialog
open={open}
TransitionComponent={Transition} // Transition fade
keepMounted
onClose={handleClose}
aria-labelledby='alert-dialog-slide-title'
aria-describedby='alert-dialog-slide-description'
fullWidth
></Dialog>

Overflow hidden with border radius not working in chrome

Not sure whether it is chrome specific bug or what, but when I am transitioning child element on a parent that has overflow hidden with border radius, the overflow is visible, while the transition is in place.
var wrapper = document.getElementsByClassName('wrapper')[0],
img = document.getElementsByTagName('img')[0];
/*
Click anywhere in the bordered area to toggle img
*/
wrapper.addEventListener('click', function() {
if (!img.className) {
img.className = 'hidden';
} else {
img.className = '';
}
}, false);
.wrapper {
overflow: hidden;
border-radius: 60px;
border: 1px solid salmon;
}
img {
width: 100%;
height: auto;
opacity: 1;
transition: opacity 1s ease;
}
.hidden {
opacity: 0;
}
<div class="wrapper">
<img src="http://static.planetminecraft.com/files/resource_media/screenshot/1211/y-you-no-work_1687402.jpg">
</div>
Here's a fiddle demonstrating the issue https://jsfiddle.net/827vuyqb/2/
Any solutions, workarounds for this?
Just position the wrapper element, and give it a z-index:
var wrapper = document.getElementsByClassName('wrapper')[0],
img = document.getElementsByTagName('img')[0];
/*
Click anywhere in the bordered area to toggle img
*/
wrapper.addEventListener('click', function() {
if (!img.className) {
img.className = 'hidden';
} else {
img.className = '';
}
}, false);
.wrapper {
overflow: hidden;
border-radius: 60px;
border: 1px solid salmon;
/*Position and z-index*/
position: relative;
z-index: 1;
}
img {
width: 100%;
height: auto;
opacity: 1;
transition: opacity 1s ease;
}
.hidden {
opacity: 0;
}
<div class="wrapper">
<img src="http://static.planetminecraft.com/files/resource_media/screenshot/1211/y-you-no-work_1687402.jpg">
</div>

Resources