Reputation: 1030
I wanted to create a slider with the following effect shown here https://codyhouse.co/demo/image-comparison-slider/index.html when clicking on the button slides are revaling each other.I created 2 buttons per slide and tried to do something like this
jQuery('#movetohappyscene').click(function(){
jQuery('.badscene').animate({ marginLeft: '-1024px','z-index':'1'}, 2000);
jQuery('.happyscene').animate({
marginLeft: '0px',
'z-index' : '2'
}, 2000);
});
jQuery('#movetobadscene').click(function(){
jQuery('.happyscene').animate({ 'z-index':'1'}, 2000);
jQuery('.badscene').animate({'z-index':'2', marginLeft: '0px'}, 2000);
});
<div class="slidecontainer">
<div class="badscene">
<a id="movetohappyscene">Click to show happy scene</a>
<img src="img/badsceneempty.png">
</div>
<div class="happyscene">
<a id="movetobadscene">Click to show sad scene</a>
<img src="img/goodscene.png">
</div>
</div>
Here is the updated fiddle
But the effect is not the same as in that slider.How I can customize my js so they will be similar?
Upvotes: 4
Views: 493
Reputation: 2036
I have a similar example to your question, but i did this in pure css.
/**
* Image slider with pure CSS
*/
.image-slider {
position:relative;
display: inline-block;
line-height: 0;
}
.image-slider > div {
position: absolute;
top: 0; bottom: 0; left: 0;
width: 25px;
max-width: 100%;
overflow: hidden;
resize: horizontal;
}
/* Cross-browser resizer styling */
.image-slider > div:before {
content: '';
position: absolute;
right: 0; bottom: 0;
width: 13px; height: 13px;
padding: 5px;
background: linear-gradient(-45deg, black 50%, transparent 0);
background-clip: content-box;
cursor: ew-resize;
-webkit-filter: drop-shadow(0 0 2px black);
filter: drop-shadow(0 0 2px red);
}
.image-slider img {
user-select: none;
max-width: 400px;
}
<div class="image-slider">
<div>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-before.jpg" />
</div>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/photoshop-face-after.jpg" />
</div>
Upvotes: 1