进行以下更新:

  1. 因为不是每个博客都有图像,因此请删除 img标记。

  2. h7标记中,将 textContent: subtitle 更新为 textContent: updated。这会在 ListView 项目的覆盖部分中放置上次更新日期。

  3. 移动位于类 item-overlaydiv之前的 h5标记。这会在 ListView 项目的主要部分中放置博客标题。

结果如下所示。

                                                        
      

若要将列表项目的颜色设置为浅蓝色,请打开 items.css 并添加此处所示的 background-color 属性。此外,在 -ms-grid-rows 属性中将第二行的大小从 90px 更改为 60px,如此处所示,因为我们只显示覆盖中的上次更新日期。

.itemspage .itemslist .item {     -ms-grid-columns: 1fr;     -ms-grid-rows: 1fr 60px;     display: -ms-grid;     height: 250px;     width: 250px;     background-color: #557EB9; }

若要为博客标题设置字体大小和边距,请将此代码添加到 items.css。

.itemspage .itemslist .win-item .item-title {     -ms-grid-row: 1;     overflow: hidden;     width: 220px;     font-size:  24px;     margin-top: 12px;     margin-left: 15px; }

更新拆分 PageControl

打开 split.html。模板中拆分页的 HTML 使用与示例数据相同的名称。我们需要更新此 div 标记中的 HTML,从而在我们的 blogPosts 数组中反映名称。

                                                                             

进行以下更新:

  1. 将 img 标记替换为新的

    ...
    节点。

  2. 在 h7 标记中,将 textContent: subtitle 改为 textContent: author。

  3. 删除 h5 标记

结果如下所示。

                        

            |                                                                      

注意,我们将管道字符用作分隔符,因为 HTML 不包含用于绘制竖线的标记。

因为我们没有包含在示例数据中的所有信息,所以从 articleSection 删除此代码可以简化页面。

                                  

若要设置文本块的颜色以及文本的项目日期、字体和边距,请打开 split.css 并添加此代码。

.splitpage .itemlistsection .itemlist .item .item-date {     -ms-grid-column:  1;     background-color: #557EB9; }      .splitpage .itemlistsection .itemlist .item .item-date .item-month{         margin-top: 12px;         margin-left: 12px;         margin-bottom: 4px;         font-weight: bold;         font-size: 28px;     }      .splitpage .itemlistsection .itemlist .item .item-date .item-day{         margin-left: 12px;         font-size: 28px;     }

若要获取我们所需的页面布局,请将此 -ms-grid-row属性从 "1" 改为 "2"。这导致页面标题填满整个第一行,并且将 ListView 和文章放在第二行。

.splitpage .articlesection {     -ms-grid-column: 2;     -ms-grid-row: 2;     -ms-grid-row-span: 2;     margin-left: 50px;     overflow-y: auto;     padding-right: 120px;     position: relative;     z-index: 0; }

现在,来试试再次运行应用吧。按 F5  可构建、部署并启动此应用。可以立即看到页面标题,但是应用检索源数据时有短暂的延迟。满足所有承诺后,可以看到在 ListView  中每个博客一个项。(此代码以满足承诺的顺序将这些项添加到 ListView 中。)点击或单击 ListView  中的项会将你带到拆分页,此拆分页包含所选博客的博客文章列表以及所选博客文章的内容。默认选中第一篇博客文章。

单击“后退”箭头可返回到项页。请注意,返回到屏幕的磁贴带有过渡动画。这是 Windows JavaScript 库中的一个功能,它支持控件以及其他用户界面元素按照 Windows 应用商店应用的 UX 指南移动。

怎么使用JavaScript和HTML创建博客阅读器

添加项详细信息 PageControl

项详细信息 PageControl 将博客文章的标题显示为自己的标题,并有一块区域包含博客文章的内容。

添加项详细信息 PageControl 的步骤:

  1. 在解决方案资源管理器中,右键单击 pages 文件夹,选择“添加”>“新建文件夹”。

  2. 将该文件夹命名为 itemDetail。

  3. 在解决方案资源管理器中,右键单击 itemDetail 文件夹,选择“添加”>“新建项”。

  4. 选择“JavaScript”>“Windows 应用商店”>“页面控件”,然后使用文件名 itemDetail.html。

  5. 单击“添加”以在 pages/itemDetail 文件夹中创建 itemDetail.css、itemDetail.html 和 itemDetail.js 文件。

打开 itemDetail.html 并更新此处所示的主要部分。此代码定义页面布局。(这是网格应用模板中包含的 itemDetail.html 页面代码的简化版本。)

            itemDetail                                                                                           Welcome to itemDetail                                            

Content goes here.

                

用以下代码替换 Main content 部分。

     
              
 

打开 itemDetail.js 并更新此处所示的 ready 函数的代码。此代码显示用户导航至此页面时的标题和内容。(这是网格应用模板中包含的 itemDetail.js 页面代码的简化版本。)

ready: function (element, options) {    // Display the appbar but hide the Full View button    var appbar = document.getElementById('appbar');    var appbarCtrl = appbar.winControl;    appbarCtrl.hideCommands(["view"], false);     var item = options && options.item ? options.item : Data.items.getAt(0);                                               element.querySelector(".titlearea .pagetitle").textContent = item.title;    element.querySelector("article .item-content").innerHTML = item.content; },

现在,我们为项详细信息页面定义样式。打开 itemDetail.css,使用此处显示的代码替换模板代码。

.itemDetail section[role=main] {     -ms-grid-row: 2;     display: block;     height: 100%;     overflow-x: auto;     position: relative;     width: 100%;     z-index: 0; }      .itemDetail section[role=main] article {         /* Define a multi-column, horizontally scrolling article by default. */         column-fill: auto;         column-gap: 80px;         column-width: 480px;         height: calc(100% - 50px);         margin-left: 120px;         width: 480px;     }          .itemDetail section[role=main] article .item-content p {             margin-bottom: 20px;             margin-right: 20px;             vertical-align: baseline;         }  @media screen and (-ms-view-state: snapped) {     .itemDetail section[role=main] article {         /* Define a single column, vertically scrolling article in snapped mode. */         -ms-grid-columns: 300px 1fr;         -ms-grid-row: 2;         -ms-grid-rows: auto 60px;         display: -ms-grid;         height: 100%;         margin-left: 20px;         overflow-x: hidden;         overflow-y: auto;         width: 300px;     }          .itemDetail section[role=main] article .item-content {             padding-bottom: 60px;         } }  @media screen and (-ms-view-state: fullscreen-portrait) {     .itemDetail section[role=main] article {         margin-left: 100px;     } }

添加带有显示项目详细信息页面命令的应用栏

我们添加一个应用栏,它包含可用于导航到项目详细信息页面的按钮,并使此按钮仅在我们位于拆分页时才显示。

打开 default.html 并取消注释此代码。

修改占位符按钮的定义,以在应用栏靠右侧远端创建一个标签为“完全视图”的按钮,如此处所示。

           

在导航至项目页面和项目详细信息页面时,我们不希望“完全视图”按钮显示在应用栏上。将此代码添加到 items.js 中的 ready 函数内以隐藏按钮。(此代码已经出现在我们创建的 ready 中的 itemDetail.js 函数内。)

// Display the appbar but hide the Full View button var appbar = document.getElementById('appbar'); var appbarCtrl = appbar.winControl; appbarCtrl.hideCommands(["view"], false);

我们导航至拆分页时,“完全视图”按钮将显示在应用栏上。将此代码添加到 split.js 中的 ready 函数内以显示按钮。

// Display the appbar and show the Full View button var appbar = document.getElementById('appbar'); var appbarCtrl = appbar.winControl; appbarCtrl.showCommands(["view"], false);

从拆分 PageControl 导航到项详细信息 PageControl

用户单击应用栏上的“完全视图”按钮时,应用导航到项详细信息 PageControl 并显示所选博客文章的标题和内容。

打开 split.js。将此变量声明添加到 utils 变量声明的后面。

// The selected item var post;

在第二次调用 querySelector之前将此语句添加到 ready 函数,以便可以先设置 this.items。此代码将 post 变量设置为用户导航至页面时第一篇博客文章的索引。

// Get the first item, which is the default selection post = this._items.getAt(0);

将此语句添加到 _selectionChanged 函数,该函数位于设置 this._itemSelectionIndex 的语句后面。此代码会将 post 变量设置为用户所选博客文章的索引。

// Get the item selected by the user post = this._items.getAt(this._itemSelectionIndex);

在 _selectionChanged 函数之外,将此事件处理程序函数添加到 post 变量声明的后面。用户单击“完全视图”按钮时即调用此处理程序。WinJS.Navigation.navigate 函数会加载项详细信息页面,并将所选的博客文章作为项传递。

function displayFullView() {     // Display the selected item in the item detail page     nav.navigate('/pages/itemDetail/itemDetail.html', { item: post }); }

将此代码添加到 ready 函数中(在我们添加的代码的之后),以显示“完全视图”按钮。此代码将我们的 displayFullView 函数注册为“完全视图”按钮的 click 事件的事件处理程序。

// Register the event handler for the Full View button document.getElementById('view').addEventListener("click", displayFullView, false);

按 F5 以运行应用。单击项目页上的项目会将你带到拆分页,此拆分页包含博客文章列表以及所选博客文章的内容。点击或单击博客文章,文章内容即显示在右侧栏中。若要显示应用栏,请右键单击,或者从底端或顶端轻扫(如果你的系统支持触摸)。

怎么使用JavaScript和HTML创建博客阅读器

点击或单击“完全视图”按钮,我们的应用将在项目详细信息页面中显示所选博客文章的内容。

怎么使用JavaScript和HTML创建博客阅读器

如果点击或单击“后退”按钮,则返回到拆分页。ListView 中的第一项被选中,它不一定是你在项目详细信息页面中选择显示的项。 你可以根据需要添加代码来保存并还原所选项。

我们的应用所使用的模板代码可以显示横向和纵向方向。旋转你的电脑,或在 Microsoft Visual Studio Express 2012 for Windows 8 的模拟器中运行你的应用,然后旋转显示器。项页外观如下所示。

怎么使用JavaScript和HTML创建博客阅读器

拆分页外观如下所示。请注意,在选择项目前,仅显示 ListView 控件。然后,博客文章以垂直方向显示。如果单击 Full View 按钮,则博客文章以水平方向显示。

怎么使用JavaScript和HTML创建博客阅读器

感谢各位的阅读,以上就是“怎么使用JavaScript和HTML创建博客阅读器”的内容了,经过本文的学习后,相信大家对怎么使用JavaScript和HTML创建博客阅读器这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


分享标题:怎么使用JavaScript和HTML创建博客阅读器
网页网址:http://tjjierui.cn/article/jccsei.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP