jquery - 像 Netflix 上的水平滚动图像

标签 jquery html css menu scroll

我正在尝试创建一个包含视频内容的网站,我想在主页上横向选择封面图片,就像 netflix 那样。

这意味着大量图片分布在屏幕大小上,并且将通过屏幕右侧/左侧的鼠标悬停箭头滚动。

截图:

http://cdn3-i.hitc-s.com/180/netflix_redesign_70590.jpg

有人知道怎么制作吗? 我正在使用 Dreamweaver 和 Muse,掌握了一些基本的 html 和 css 技能,使用了一些 jquery 代码,但我还不太熟练。

再见,罗伯特

最佳答案

从一些基本的 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 文件夹中的截屏,还有一个库用于添加人字形图标,但您可以使用任何东西。

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);
    }
});

结果:

enter image description here

注意:您不需要上面的“add_icon”功能。您可以简单地为左右事件添加自己的按钮或图标。

关于jquery - 像 Netflix 上的水平滚动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28013179/

相关文章:

html - 在较小的父 div 中缩小具有不同宽度的图像

javascript - JQuery 是否适用于具有相同 ID 的所有按钮(不同页面)

javascript - (Spotify Web API) 创建新播放列表 - POST 请求返回 'Error 403 (Forbidden)'

javascript - jQueryUI 对话框的顺序是否有所不同(也许只是 TinyMCE)?

html - Sencha Touch——数据 View 内的旋转木马或水平滚动?

javascript - 无法使用javascript更改div区域的背景?

html - 如何将大于其容器的字符居中

javascript - 旋转木马图像相同高度

javascript - 筛选元素并仅选择带有文本的元素

css - 如何将样式应用于 GitBook 中的代码块?