JQuery Arrow键滑块的东西

时间:2015-09-30 19:19:08

标签: javascript jquery html css

好的,抱歉标题,我想不出要叫什么。

我正在设计HTML5和JavaScript的智能电视界面。到目前为止我得到的是div充满假电影名称(用于测试目的)。我不认为它一直在运行,但这是一个演示:https://xviuw-cheapskate01.c9.io/

我想要做的是检测所选的div是否在它的第3到第一个div和它的第3个到第一个div之间&# 39; s班。如果是,我希望整个包含div的左值移动-230px。

我算出了这个等式。虽然它没有用,但你应该得到这个想法。

(index - 2) * -220 + "px"

我尝试过很多东西,但都没有。

这是我的代码。

JS:

var selected;

$(document).ready(function() {
  $(".movie-section .movie:nth-child(1)").addClass("movie-selected");
  selected = $(".movie-selected");

  $('html').keydown(function(e){
    if (e.keyCode == 39) {
      if (selected.is($(".movie-section .movie:last-child"))) {

      } else {
        $( ".movie-selected + .movie" ).addClass("movie-selected");
        $( selected ).removeClass("movie-selected");
        selected = $(".movie-selected");

      }
    }

    if (e.keyCode == 37) {
      if (selected.is($(".movie-section .movie:nth-child(1)"))) {

      } else {
        $( ".movie-selected" ).prev().addClass("movie-selected");
        $( selected ).removeClass("movie-selected");
        selected = $(".movie-selected");
      }
    }
  });

});

HTML:

<!DOCTYPE html>
<html ng-app="homeApp">
    <head>
        <link rel="stylesheet" href="css/style.css" type="text/css" />
        <title>XViuw</title>
        <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
        <script type="text/javascript" src="js/parallax.min.js"></script>
        <script type="text/javascript" src="js/angular.min.js"></script>
        <script type="text/javascript" src="js/main.js"></script>
    </head>
    <body>
        <div class="parallax-window" data-parallax="scroll" data-image-src="img/blurcity.png"></div>
        <div ng-controller="Controller as controller">
            <header class="headerbar">

            </header>
            <div class="movie-section">
                <div ng-repeat="movie in movies" class="movie">
                    <div class="thumbnail"> 
                        <img ng-src="{{ movie.cover }}"> 
                        <p class="title">{{ movie.name }}</p>
                        <p>{{movie.rating}}</p>
                        <p>{{movie.length}}</p>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

的CSS:

@import url(https://fonts.googleapis.com/css?family=Roboto);
@font-face {
    font-family: 'Material Icons';
    font-style: normal;
    font-weight: 400;
    src: url(../fonts/MaterialIcons-Regular.ttf);
}

body, html {
    width: 100%;
    height: 100%;
    font-family: 'Roboto', sans-serif;
    margin: 0;
}

.parallax-window {
    min-height: 100%;
    background: transparent;
}

.headerbar {
    width: 100%;
    height: 100px;
    position: fixed;
    top: 0;
    box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}

.movie-section {
    height: 200px;
    position: fixed;
    top: 140px;
    left: 0;
    white-space: nowrap;
    font-family: 'Roboto', sans-serif;
    -webkit-transition: left 300ms, right 300ms;
    transition: left 300ms, right 300ms;
}

.movie {
    margin: 0 10px;
    width: 180px;
    height: 180px;
    padding: 10px 20px;
    text-align: center;
    color: white;
    display: inline-block;
    border-radius: 2px;
    -webkit-transition: background 150ms;
    transition: background 150ms;
} 

.movie-selected {
    background: white;
    color: #5f5f5f;
}

.movie-selected:hover {
    background: white !important;
}

.title {
    text-overflow: ellipsis;
    width: 175px;
    white-space: nowrap;
    overflow: hidden;
}

.movie:hover {
    background: rgba( 0, 0, 0, 0.4);
}

.thumbnail > img {
    width: 160px;
    height: 100px;
}

.thumbnail > p {
    margin: 0;
}

.material-icons {
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;  /* Preferred icon size */
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
    word-wrap: normal;


white-space: nowrap;
  direction: ltr;

  /* Support for all WebKit browsers. */
  -webkit-font-smoothing: antialiased;
  /* Support for Safari and Chrome. */
  text-rendering: optimizeLegibility;

  /* Support for Firefox. */
  -moz-osx-font-smoothing: grayscale;

  /* Support for IE. */
  font-feature-settings: 'liga';
}

我需要添加什么?

0 个答案:

没有答案