我想创建一个滑块,其效果如下所示
https://codyhouse.co/demo/image-comparison-slider/index.html,当点击按钮时,幻灯片互相重新评估.我为每个幻灯片创建了2个按钮并试图做这样的事情
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>
这是更新的fiddle
但效果与那个滑块不一样.我如何定制我的js以便它们会相似?
最佳答案 我对你的问题有一个类似的例子,但我在纯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>