我正在尝试创建像this page这样的视频突出显示功能。当每个视频滚动到页面的中心时,该视频将突出显示。但是,不是右侧边栏上的网站地图内容,每个视频的标题/说明都会突出显示并垂直居中。像这样:
这是我到目前为止所拥有的:
http://jsfiddle.net/annablabber/gw9yoq06/4/
HTML
<div class="videos-container">
<ul class="video-info">
<li><div class="title">Title of video</div><div class="description">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div></li>
<li><div class="title">Title of video</div><div class="description">Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div></li>
<li><div class="title">Title of video</div><div class="description">Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</div></li>
<li><div class="title">Title of video</div><div class="description">Excepteur sint occaecat cupidatat non proident.</div></li>
<li><div class="title">Title of video</div><div class="description">sunt in culpa qui officia deserunt mollit anim id est laborum.</div></li>
<li><div class="title">Title of video</div><div class="description">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.</div></li>
<li><div class="title">Title of video</div><div class="description">Totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.</div></li>
<li><div class="title">Title of video</div><div class="description">Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</div></li>
<li><div class="title">Title of video</div><div class="description">Neque porro quisquam est.</div></li>
<li><div class="title">Title of video</div><div class="description">Qui dolorem ipsum quia dolor sit amet, consectetur.</div></li>
</ul>
<div class="videos">
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4" loop></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4" loop></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4" loop></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4"></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4"></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4"></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4"></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4"></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4"></video></div>
<div class="video-container"><video poster="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.jpg" preload="auto" src="http://graphics8.nytimes.com/newsgraphics/2013/07/21/silk-road/assets/media/driveby_970.mp4"></video></div>
</div>
</div>
CSS
/**
* Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/)
* http://cssreset.com
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/* End CSS reset */
body {
height: 100%;
}
.videos-container {
width: 400px;
position: relative;
border: 1px solid red;
}
.video-container {
position: relative;
width: 400px;
height: 300px;
margin-bottom: 33px;
background-color: #000;
}
video {
width: 100%;
opacity: .4;
-moz-transition: opacity .5s;
-webkit-transition: opacity .5s;
-o-transition: opacity .5s;
transiton: opacity .5s;
}
video.highlighted {
opacity: 1;
}
.video-info {
position: fixed;
z-index: 99999;
top: 0;
right: 0;
width: 240px;
}
.video-info li {
opacity: .7;
margin-bottom: 27px;
}
.video-info li .title {
font-size: 18px;
}
.video-info li .description {
font-size: 16px;
line-height: 180%;
letter-spacing: .04em;
display: none;
}
.video-info li.highlighted {
margin-bottom: 56px;
opacity: 1;
}
.video-info li.highlighted .title {
font-size: 28px;
font-weight: 500;
margin-bottom: 16px;
letter-spacing: .03em;
}
.video-info li.highlighted .description {
display: block;
}
的JavaScript / jQuery的
function isScrolledIntoView(elem)
{
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return ((docViewTop < elemTop) && (docViewBottom > elemBottom));
}
$(window).scroll(function() {
$('video').each(function() {
if (isScrolledIntoView(this)) {
// Find out which video it is
var currentIndex = $('video').index(this);
// Highlight the associated video title/description
$(".video-info li:eq(" + currentIndex + ")").addClass("highlighted").attr('id', 'rectangle');
// Vertically center highlighted video title/description
var viewportCenter = $(window).height() / 2;
var rect = document.getElementById("rectangle").getBoundingClientRect();
var liCenter = rect.top + $("li.highlighted").height()/2;
var verticalDifference = viewportCenter - liCenter;
$(".video-info").css("-webkit-transform", "translateY(" + verticalDifference + "px)");
// Remove 'highlighted' class from other videos
$("video").removeClass('highlighted');
// Add 'highlighted' to this video
$(this).addClass('highlighted');
// Play this video
$(this).get(0).play();
} else {
// Remove 'highlighted' class on video
$(this).removeClass('highlighted');
// Pause video
$(this).get(0).pause();
// Pause video
var currentIndex = $('video').index(this);
$(".video-info li:eq(" + currentIndex + ")").removeClass("highlighted");
}
});
});
视频突出显示和描述突出显示的CSS样式和jQuery工作得很好,但有一些问题:
关于如何调整我的代码以便:
的任何想法提前致谢:)