当前位置: 首页 > 编程日记 > 正文

随机网络构建_构建随机报价机

随机网络构建

by Ayo Isaiah

通过Ayo Isaiah

构建随机报价机 (Building a Random Quote Machine)

I really wasn’t entirely satisfied with my first attempt at building a Random Quote Generator on Free Code Camp. It was ugly, and the quotes were too long, so I didn’t bother to implement the “tweet” functionality. It just didn’t make any sense to do that.

我对首次在Free Code Camp上构建随机报价生成器的尝试并不完全满意。 这很丑陋,引号太长,所以我不必费心实现“ tweet”功能。 这样做没有任何意义。

So after I finished with the Pomodoro Clock Project, I felt a strong desire to revisit my Random Quote Machine and start over with a different approach.

因此,在完成Pomodoro Clock Project之后 ,我强烈希望重新访问我的随机报价机,并从另一种方法开始。

I wanted a more interesting design, with a few animations. I also had this idea of putting the quotes into different categories, so that users can view quotes from their favorite categories.

我想要一个更有趣的设计,并带有一些动画。 我也有将报价分为不同类别的想法,以便用户可以查看自己喜欢的类别中的报价。

My exams were over, so I had enough time on my hands to finish it off.

我的考试结束了,所以我手上有足够的时间完成考试。

逻辑 (Logic)

I settled on eight categories for the quotes and collected 25 quotes for each one. Each category was an array of objects with quote and author properties, so that I could retrieve each one easily.

我将报价分为八个类别,每个类别都收集了25个报价。 每个类别都是带有引号和作者属性的对象数组,因此我可以轻松检索每个类别。

Then I made a function to put the quotes in the HTML once the next quote button is clicked and a similar function for the “previous quote” button.

然后,我创建了一个函数,一旦单击了下一个引号按钮,便将引号放入HTML中,并为“上一个引号”按钮提供了类似的功能。

If you look at the code you will see that the quotes aren’t generated randomly at all, but instead they iterate from the first to the last and back again. That’s an intentional design choice I made.

如果看一下代码,您会发现引号根本不是随机生成的,而是从第一个到最后一个,然后再返回一次。 这是我故意设计的选择。

设计 (Design)

What annoyed me the most about that first attempt was not even really how it worked, but how it looked. So the design was what I concentrated on for the most part on this project.

第一次尝试让我最烦恼的不是它的工作原理,而是它的外观。 因此,设计是我大部分时间专注于该项目的内容。

The first thing I did was to list out all the things I wanted my app to do and how I wanted it to look. I’ve learnt over time that the best way to approach anything is to break it down into simple actionable steps so that is what I did here using Workflowy.

我要做的第一件事是列出我希望应用程序执行的所有操作以及其外观。 随着时间的推移,我了解到,解决任何问题的最佳方法是将其分解为简单的可操作步骤,这就是我在这里使用Workflowy所做的事情。

I’ve always used Skeleton CSS boilerplate whenever I want to make a grid based layout so I continued with it for this one also.

每当我想进行基于网格的布局时,我总是使用Skeleton CSS样板,因此我也继续使用它。

This time though, I used the Sass version which made it easy to change a few variables and customise it a bit without touching the original files.

不过,这次,我使用了Sass版本 ,该版本可以轻松更改一些变量并对其进行一些自定义,而无需接触原始文件。

Once that was in place, I commenced work on the design of the landing page. In my mind’s eye, I wanted a 2x4 grid with cards for each section and a headline at top. That was easy enough.

到位后,我便开始着陆页的设计工作。 在我眼中,我想要一个2x4的网格,每个部分都有卡片,顶部有一个标题。 那很容易。

Bam! I had my grid in place. The next thing was to figure out how I was going to style the quotes page and use animations to switch between both pages.

am! 我的网格到位了。 接下来的事情是弄清楚我将如何为报价页面设置样式并使用动画在两个页面之间切换。

The quotes page took me a bit more time to finish. I had a navigation bar at the top for switching between sections and box in the middle where the quotes would be displayed. The buttons to show the quotes were at the bottom.

报价页面花了我更多时间来完成。 我在顶部有一个导航栏,用于在显示报价的中间部分和框之间进行切换。 显示报价的按钮在底部。

An idea that popped into my head at this point was to change the background image as the user moves between sections. The background image was to correspond with the featured image in the cards on the home page.

此时出现在我脑海中的一个想法是,当用户在各部分之间移动时,更改背景图像。 背景图像应与主页上卡片中的特色图像相对应。

I also wanted the change to be smooth with subtle animations so I used the CSS transition property for this purpose and it did work well on Chrome but I couldn’t get it to work on Firefox (if anyone know how to fix this, please let me know).

我还希望更改能够在平滑的动画效果下保持平滑,因此我为此使用了CSS transition属性,它在Chrome上效果很好,但在Firefox上却无法使用(如果有人知道如何解决此问题,请让我知道)。

Once I had both layouts sorted, it was time to link the two pages with an animation. My first thought was to use CSS animations but I didn’t get anywhere so I sought out jQuery animations instead. After some experimenting, I found what I wanted. The slideUp() andslideDown() functions were perfect for what I needed.

对两种布局进行排序后,就该将两个页面与动画链接起来了。 我最初的想法是使用CSS动画,但是我什么也没做,所以我改用了jQuery动画。 经过一些试验,我找到了想要的东西。 slideUp()和slideDown()函数非常适合我需要的功能。

Basically, once you click on any of the sections on the homepage, the quotes page will slide into view and you can view quotes from the different sections. Similarly, when you click the home button on the navigation bar, the page slides down to reveal the homepage.

基本上,一旦您单击主页上的任何部分,报价页面就会滑入视图,您可以查看不同部分的报价。 同样,当您单击导航栏上的主页按钮时,页面会向下滑动以显示主页。

So that was that.

就是这样。

All I did from that point was to replace the placeholder images with real images and use some Google fonts to spruce things up. Lastly, I did the tweet button.

从那时起,我所做的就是将占位符图像替换为真实图像,并使用一些Google字体来修饰内容。 最后,我做了推特按钮。

You can view the final version on CodePen.

您可以在CodePen上查看最终版本 。

得到教训 (Lessons Learned)

In the course of working on this project I learned a few valuable lessons:

在进行该项目的过程中,我吸取了一些宝贵的经验教训:

  • In some cases, using background images can give you more control and more flexibility with images of different height because you can set background-size: cover and it won’t overflow the container. In addition, you can create some cool hover effects like I did with the featured images on the landing page. I didn’t always know this but someone on the CodeNewbie Slack group pointed this out to me.

    在某些情况下,使用背景图像可以为您提供不同高度的图像的更多控制权和更大的灵活性,因为您可以设置background-size:cover,并且不会溢出容器。 此外,您可以创建一些很酷的悬停效果,就像我对目标网页上的精选图片所做的那样。 我并不总是知道这一点,但是CodeNewbie Slack小组的某人向我指出了这一点。

  • I also learnt how to break down my Sass files into partials and import them into the main stylesheet. This helps for organisation and makes fixing things easy. I have a working architecture I’m using and it’s not perfect but I’ll improve on that over time.

    我还学习了如何将Sass文件分解为局部文件并将其导入主样式表。 这有助于组织工作,并使修复工作变得容易。 我有一个正在使用的工作架构,虽然它并不完美,但随着时间的推移我会对此进行改进。

I’ll love to hear your thoughts on my approach and what things I could improve on so a comment or two will be greatly appreciated.

我很想听听您对我的方法的想法以及我可以改进的地方,因此,不胜感激。

接下来 (Next up)

I’ll be working on the “Show the Local Weather” project this weekend and I hope to have it done by Sunday. This will be my first real experience with using an API and I hope I get it right quickly enough.

我将在本周末进行“ 显示当地天气 ”项目,希望在周日之前完成。 这将是我第一次使用API​​的真实经验,我希望我能尽快完成。

I will write a similar post on that project next week so keep an eye out for that one.

下周我将在该项目上写一篇类似的文章,因此请密切注意该项目。

If you want to reach out or connect with me, you can find me on Twitter or email me.

如果您想联系我或与我联系,可以在Twitter上找到我或给我发送电子邮件 。

A version of this post was published on my personal blog

这篇文章的一个版本发布在我的个人博客上

翻译自: https://www.freecodecamp.org/news/building-a-random-quote-machine-project-6e8d10430f4a/

随机网络构建

相关文章:

20145231 《信息安全系统设计基础》第11周学习总结

20145231《信息安全系统设计基础》第11周学习总结 教材学习内容总结 异常 异常是异常控制流的一种形式,由硬件和操作系统实现。简单来说,就是控制流中的突变。 出现异常的处理方式: 1.处理器检测到有异常发生 2.通过异常表,进行间…

JAR命令使用

jar 命令详解 jar 是随 JDK 安装的,在 JDK 安装目录下的 bin 目录中,Windows 下文件名为 jar.exe,Linux 下文件名为 jar。它的运行需要用到 JDK 安装目录下 lib 目录中的 tools.jar 文件。不过我们除了安装 JDK 什么也不需要做,因…

捍卫者usb管理控制系统_捍卫超模块化JavaScript

捍卫者usb管理控制系统by Mike Groseclose通过Mike Groseclose 捍卫超模块化JavaScript (In Defense of Hyper Modular JavaScript) Last week npmgate was a big topic for the JavaScript community. For those of you who haven’t been following what happened, here’s …

Android开发——布局性能优化的一些技巧(一)

0. 前言上一篇我们分析了为什么LinearLayout会比RelativeLayout性能更高,意义在于分析了这两种布局的实现源码,算是对一个小结论的证明过程,但是对布局性能的优化效果,对这两种布局的选择远不如减少布局层级、避免过分绘制、按需加…

1-RAC基础

1 安装 pod ‘ReactiveObjC’ RAC 其实大大减少了代码量 2 基本使用 // 0 RAC 中最为常见的类 信号类/*RACSignal:信号类1.通过RACSignal 创建1个信号(默认:冷信号)2.通过订阅者,订阅信号信号(变成:热信号…

static用法总结

C的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static。前者应用于普通变量和函数,不涉及类;后者主要说明static在类中的作用。 一、面向过程设计中的static1、静态全局变量2、静态局部变量3、静态函数二、面向对象的…

小程序 缩放_缩放流星应用程序的初体验

小程序 缩放by Elie Steinbock埃莉斯坦博克(Elie Steinbock) 缩放流星应用程序的初体验 (First Experiences Scaling a Meteor App) I recently went through the challenge and ordeal of having to scale my Meteor app. It’s a project that had already been running in …

SQL Server Lock Escalation - 锁升级

Articles Locking in Microsoft SQL Server (Part 12 – Lock Escalation) http://dba.stackexchange.com/questions/12864/what-is-lock-escalation 2008 R2 Lock Escalation (Database Engine)---Forward from Locking in Microsoft SQL Server (Part 12 – Lock Escalation)…

Jzzhu and Chocolate

CF#257 div2 C:http://codeforces.com/contest/450/problem/C 题意:n*m的方格,每次可以横着或者纵向的切一刀,问切k之后,最小的最大是多少。 题解:比赛的时候没有想到怎么处理,看了别人的题解,才…

2-RACommand

RACommand RACCommand 就是命令 // RACCommand 就是命令// 0 创建一个CMD 穿进去一个用于构建RACSignal的Block参数来初始化RACommandRACCommand *cmd [[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {// 此处是cmd 执行的输入源NSLog(…

玻璃上的编码喜悦(+ 10史诗般的Epigrams)

by Den McHenry丹麦克亨利(Den McHenry) 玻璃上的编码喜悦( 10史诗般的Epigrams) (Perlis on Coding Joy ( 10 Epic Epigrams)) Alan J. Perlis was the first recipient of the Turing Award. He’s possibly most remembered today for his Epigrams on Programming, which …

【Android】Activity生命周期(亲测)

测试手机:Nexus 5 系统:4.4 一、测试 测试代码: 1 package com.example.androidalarm;2 3 import android.app.Activity;4 import android.content.Context;5 import android.content.res.Configuration;6 import android.os.Bundle;7 impo…

angularjs 学习笔记 简单基础

angularjs是谷歌公司的一个项目,弥补了hml在构建方面的不足,通过指令(directive)来扩展html标签,可以使开发者使用html来声明动态内容。 angularjs主要用来开发单页应用(SPA)为主的项目。 angul…

3-RACSignal 常用方法

RACSingal的常用方法 一 基本使用 1map // 0 创建信号提供者// RACSubject,既能发送信号,又能订阅信号// 多用于代理,相当于OC里的delegate或者回调blockRACSubject *subject [RACSubject subject];// 1 绑定信号RACSignal *bindSignal …

javascript迭代_探索JavaScript迭代

javascript迭代by Festus K. Yangani由Festus K.Yangani 探索JavaScript迭代 (Exploring JavaScript Iteration) Loops allow programs to perform repetitive tasks, such as iterating through an array, while adhering to the DRY principle (Don’t Repeat Yourself). Th…

4 RACMulticastConnection 连接类

# RACMulticastConnection信号被多次订阅如果一个信号多次被订阅&#xff0c;那么代码块代码会多次被执行。objective-c// 创建信号RACSignal *sg1 [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {NSLog("网络请求…

ie6下常见的bug 调整页面兼容性

ie6下常见的bug 我们布局页面&#xff0c;首先符合标准&#xff0c;如何写一个页面的标准性&#xff1f; 但是ie6等浏览器本身就比较特殊&#xff0c;bug比较多&#xff0c;兵法云&#xff0c;知己知彼百战百胜。我们需要了解ie6的一些常见bug&#xff0c;这样&#xff0c;更好…

Cacti安装详细步骤

Cacti安装详细步骤 前提LNMP或LAMP架构已搭建完成 一、cacti概述 1. cacti是用php语言实现的一个软件&#xff0c;它的主要功能是用snmp服务获取数据&#xff0c;然后用rrdtool储存和更新数据&#xff0c;当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此&#xff0…

为什么使用单页应用_为什么我讨厌您的单页应用

为什么使用单页应用by Stefan Tilkov斯蒂芬蒂尔科夫(Stefan Tilkov) 为什么我讨厌您的单页应用 (Why I hate your Single Page App) Okay, now that I have your attention, let me say that I don’t really hate your single page app. I just find it highly annoying, unl…

marquee实现文字移动效果;js+div实现文字无缝移动效果

1.marquee实现文字移动&#xff1a; <marquee width"220px;" scrollamount"5" onmouseover"this.stop()" onmouseout"this.start()" ><p style"letter-spacing:2px;width: 1px;">欢迎您登录拜博医疗口腔集团内部…

URAL 1203 Scientific Conference(贪心 || DP)

Scientific Conference 之前一直在刷计算几何&#xff0c;邀请赛连计算几何的毛都买见着&#xff0c;暑假这一段时间就做多校&#xff0c;补多校的题目&#xff0c;刷一下一直薄弱的DP。多校如果有计算几何一定要干掉-。- 题意&#xff1a;给你N个报告会的开始时间跟结束时间&a…

5- RAC 集合 RACTuple RACSequence

RAC 集合 RACTuple RACSequence // 0 RACTuple 就是一个数组/*RACTuple 就是一个数组*/RACTuple *tp1 [RACTuple tupleWithObjects:"5",5,1, nil];RACTuple *tp2 [RACTuple tupleWithObjectsFromArray:["11","22","33"]];NSLog(&quo…

测试开发人员与开发人员_如何升级为开发人员

测试开发人员与开发人员by Will Hughes威尔休斯(Will Hughes) 如何升级为开发人员 (How to Level up as a Developer) Being a productive developer is something you can learn through experience, books, or trial and error. But, one of the best ways to become a prod…

ORA-00959: tablespace 'PSAPTEMP' does not exist

错误 : ORA-00959: tablespace PSAPTEMP does not exist 解决办法: CREATE TEMPORARY TABLESPACE PSAPTEMP TEMPFILE E:/Oracle/ORC/sapdata3/temp_1/temp.data1 SIZE 500M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE unlimited EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;ALTER …

RAC rac_liftSelector

RAC rac_liftSelector 主要是用于线程的同步 - (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.// rac_liftSelector// 类似于dispatch_group 中的组// 多线程中的组 等所有的请求都完毕之后 去更新UIRAC…

随笔记一些莆田话

莆田话是闽南话和福州话混合的产物&#xff0c;当然也是古汉语保留至今的珍宝。很多莆田话的词语是有源可溯的。这里记录一些平常想到的又可能不为人知的词语。 莆田话——普通话解释 物件——东西 万代——很多 先生——老师&#xff08;先生白读时是老师的意思&#xff09;&a…

JavaScript库和API

by Adam Recvlohe通过亚当雷夫洛厄(Adam Recvlohe) API就像一盒巧克力 (APIs are like a box of chocolates) If you have written JavaScript for the DOM before, then you probably know how unwieldy it can get. I mean getElementById is seven syllables and 14 charac…

Hadoop 全分布模式 平台搭建

现将博客搬家至CSDN&#xff0c;博主改去CSDN玩玩~ 传送门&#xff1a;http://blog.csdn.net/sinat_28177969/article/details/54138163 Ps&#xff1a;主要答疑区在本帖最下方&#xff0c;疑点会标注出来。个人在配置过程中遇到的困难都会此列举。 实验介绍&#xff1a; 本次实…

iOS 使用fastlane自动化打包步骤

加粗样式### iOS 使用fastlane 自动打包步骤 &#xff01;参考 1 查看ruby版本信息 本机是否安装ruby ruby -v 2 安装xcode命令行工具 点击同意即可 xcode-select --install 3 安装fastlane 键入如下命令 sudo gem install fastlane -NV4 使用 1 打开终端 cd 进入到要打包的…

今天开始搞CentOS 7

今天开始搞CentOS 7,安装过程很顺利&#xff0c;界面相当友好。转载于:https://www.cnblogs.com/lixd/p/3868649.html