javascript - 在 Samsung Smart TV 应用程序中通过 Remote 导航

标签 javascript jquery html samsung-smart-tv

我正在创建三星智能电视 javascript 应用程序,HTML 页面已完成,现在是时候在其中集成远程控制选项了。

我的应用程序包含不同 channel 等的选项卡/图像,当用户通过远程选择时,他将被重定向到。现在的问题是这个导航将如何工作??用户如何使用 Remote 在这些 channel 选项卡上左右移动或上下移动?

在三星智能电视文档中,他们提供了有关其 keystore 的信息,但我如何在我的应用程序中使用它来移动到不同的元素?

最佳答案

无法为您提供完整的解决方案,但至少可以提供一些我们如何做到这一点的实践。

您可以将 HTML 组织到不同的导航区域和类型中。导航区域具有导航类型,通常是列表网格

JavaScript 导航 Controller 跟踪您所在的区域。它还处理按键(上/下/左/右/输入),并根据导航类型确定下一个要突出显示的项目。

假设您有一个标签列表:

<div id="maintabs" class="tabs nav-current-zone" data-nav-type="list">
    <span class="tab nav-current-item">Tab 1</span>
    <span class="tab">Tab 2</span>
    <span class="tab">Tab 3</span>
</div>

JavaScript 通常看起来像这样:

if($(".nav-current-zone").data("nav-type") === "list"){
    if(key === "down"){
       var currentItem = $(currentZone).find("nav-current-item");
       var nextItem =  $(currentItem).next();
       $(currentItem).removeClass("nav-current-item");
       $(nextItem).addClass("nav-current-item");
    } else if(key === "up"){
    ...
}

如果您位于列表的顶部/底部并导航到列表之外怎么办?在这种情况下,您可以什么都不做或定义一个其他区域进入。

<div id="maintabs" data-nav-type="list" data-nav-leave-down="anotherZone">
    ...
</div>

<div id="anotherZone" data-nav-type="list" data-nav-leave-up="maintabs">
    ...
</div>

所以让我们来处理这个:

if(key === "down"){
   var nextItem =  $(currentZone).find("nav-current").next();
   if($(next).size() === 0){
        var nextZone = $(currentZone).data("nav-leave-down");
        //navigate to the other zone
   }
}

关于javascript - 在 Samsung Smart TV 应用程序中通过 Remote 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10800122/

相关文章:

html - 如何调整复选框周围的点击区域?

html - 如何在html中为单个div中的两个图像制作zoomIn动画

javascript - 从 BrowserWindow Electron 类扩展时出错

php - 动态创建多个上传文件

javascript - Jquery - .offset().left() - 百分比

javascript - 如何使用 Jquery 添加多个具有不同起点的弹跳 div

jquery - CSS3 rotate3d 不准确

javascript - 整数值在输入文本字段中是否表现为字符串?

javascript - 返回HTML5页面时如何触发函数? (javascript)

JavaScript 包括另一种