从一些基本的 CSS 样式开始:
这将涵盖 Netflix 的基本外观:
body {
background: #141414;
}
#hold_images {
display: inline-block;
white-space: nowrap;
}
#icon_right {
right: 20;
cursor: pointer;
margin-top: -200px;
position: fixed;
}
#icon_left {
left: 20;
cursor: pointer;
margin-top: -200px;
position: fixed;
}
.transition {
-webkit-transform: scale(1.2);
-moz-transform: scale(1.2);
-o-transform: scale(1.2);
transform: scale(1.2);
}
img {
-webkit-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
-ms-transition: all .4s ease-in-out;
cursor: pointer;
}
在你的 body 中添加一个 div 来保存图片:
<body>
<div id='hold_images'></div>
</body>
使用 jQuery 处理图像和图标的附加、图像悬停和平滑滚动:
图像是保存到 img 文件夹中的截屏,并使用了一个库来添加 V 形图标,但您可以使用任何东西。
images = {
"1" : "img/1.png",
"2" : "img/2.png",
"3" : "img/3.png",
"4" : "img/4.png",
"5" : "img/5.png",
"6" : "img/6.png",
"7" : "img/7.png",
"8" : "img/8.png",
"9" : "img/9.png",
"10" : "img/10.png"
}
Object.keys(images).forEach(function(path) {
$('#hold_images').append("<img class='my_img' width=200 height=400 src=" + images[path] + ">");
});
$('body').append("<i id='icon_right'></i>");
$('body').append("<i id='icon_left'></i>");
add_icon('#icon_right', 'fa fa-chevron-right', '40px', 'white');
add_icon('#icon_left', 'fa fa-chevron-left', '40px', 'white');
$(document).ready(function(){
$('.my_img').hover(function() {
$(this).addClass('transition');
}, function() {
$(this).removeClass('transition');
});
});
$(document).on('click', '#icon_right, #icon_left', function() {
if($(this).attr('id') == 'icon_right') {
$('body').animate({scrollLeft: 1000}, 800);
} else {
$('body').animate({scrollLeft: -1000}, 800);
}
});
结果: