install :  package 설치할때 사용하는 명령어, 가장 많이 쓰이고 대표적이다. 

npm install --save react-native-device-info

link

react-native link react-native-device-info
반응형

Lodash is a JavaScript library which provides utility functions for common programming tasks using the functional programming paradigm. Wikipedia

Initial release date: April 23, 2012 / LicenseMIT

Lodash는 함수형 프로그래밍 패러다임을 사용하여 일반적인 프로그래밍 작업을 위한 유틸리티 기능을 제공하는 JavaScript 라이브러리입니다.

 


 

A modern JavaScript utility library delivering modularity, performance & extras. 

모듈성, 성능 및 추가 기능을 제공하는 최신 자바스크립트 유틸리티 라이브러리입니다.


 

다운로드 | Download

Lodash is released under the MIT license & supports modern environments.Review the build differences & pick one that’s right for you.

Lodash는 MIT 라이선스에 따라 출시되었으며 최신 환경을 지원합니다. 빌드 차이점을 검토하고 적합한 것을 선택하십시오.

설치 방법 | Installation

브라우저에서 바로 사용하기 | In a browser:

<script src="lodash.js"></script>

NPM 사용하기 | Using npm:

$ npm i -g npm
$ npm i --save lodash

Node에서 사용하기 | In Node.js:

// Load the full build.
var _ = require('lodash');
// Load the core build.
var _ = require('lodash/core');
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp');

// Load method categories.
var array = require('lodash/array');
var object = require('lodash/fp/object');

// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var at = require('lodash/at');
var curryN = require('lodash/fp/curryN');
 

노트 | Note:
Node.js < 6 REPL 에서 Lodash 사용을 위해 n_를 설치합니다.  

왜 Lodash 인가? | Why Lodash?

Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.Lodash’s modular methods are great for:

Lodash는 배열, 숫자, 객체, 문자열 등으로 작업하는 번거로움을 없애 JavaScript를 더 쉽게 만듭니다.Lodash의 모듈식 메서드는 다음과 같은 경우에 적합합니다.

  • Iterating arrays, objects, & strings 배열, 객체 및 문자열 반복
  • Manipulating & testing values 값 조작 및 테스트
  • Creating composite functions 복합 함수 만들기

 

모듈 형식 | Module Formats

Lodash is available in a variety of builds & module formats.

Lodash는 다양한 빌드 및 모듈 형식으로 제공됩니다.

보완 도구 | Complementary Tools

  • futil-js is a set of functional utilities designed to complement lodash

futil-js는 lodash를 보완하도록 설계된 기능 유틸리티 세트입니다.

추가 자료 | Further Reading

지원 | Support

Chrome 74-75, Firefox 66-67, IE 11, Edge 18, Safari 11-12, & Node.js 8-12에서 테스트 되었습니다. 

 

 

Lodash

_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });_.partition([1, 2, 3, 4], n => n % 2);DownloadLodash is released under the MIT license & supports modern environments. Review the build differences & pick one that’s right for you.InstallationIn

lodash.com

 

반응형

'Frontend > Javascript' 카테고리의 다른 글

[JS] Array.Sort() 사용하기  (0) 2019.09.04

#제공 데이터 중 최신컨텐츠 우선으로 정렬하고, 정렬순번으로 오름차순으로 정렬하기

d.list.sort((a,b) => a.newYn > b.newYn ? -1 : (a.sortNum > b.sortNum ? 1:-1));

 

- 사용방법

[].sort(conditionFunction);
//1,2,3,8,9 오름차순
var arr = [2, 9, 8, 3, 1]
print(arr.sort()); 
 
//9,8,3,2,1 내림차순
//#1
var arr = [2, 9, 8, 3, 1];
console.log(arr.sort(function(a,b){
	return b-a;
})); 

//#2
var arr = [2, 9, 8, 3, 1];
console.log(arr.sort(orderByDesc)); 

function orderByDesc(a,b){
	return b-a;
} 

//#3
var arr = [2, 9, 8, 3, 1];
console.log(arr.sort((a,b)=> b-a));
 

 

반응형

'Frontend > Javascript' 카테고리의 다른 글

[JS] Lodash?  (6) 2024.09.12

convert this string into array of objects

using the JSON native parser, as it is not only faster than the eval(), it's also more secure.

Native JSON parser is already available in:

Firefox 3.5+ IE 8+ Opera 10.5+ Safari Safari 4.0.3+ Chrome (don't know which version)

 

var myJSONString = '{ "a": 1, "b": 2 }';
myObject = JSON.parse(myJSONString);

 

http://stackoverflow.com/questions/3473639/best-way-to-convert-string-to-array-of-object-in-javascript

 

반응형

'Frontend > HTML5' 카테고리의 다른 글

Get Start Less  (0) 2014.09.02
.prependTo()  (0) 2014.08.22
make an Interactive Website 5 coding  (0) 2014.08.22
margin by codecademy  (0) 2014.08.21
ASP.NET MVC4 WEB API  (1) 2013.10.22




http://lesscss.org/



Less is a CSS pre-processor, meaning that it extends the CSS language, adding features that allow variables, mixins, functions and many other techniques that allow you to make CSS that is more maintainable, themable and extendable.

Less runs inside Node, in the browser and inside Rhino. There are also many 3rd party tools that allow you to compile your files and watch for changes.

For example:

@base: #f938ab;

.box-shadow(@style, @c) when (iscolor(@c)) {
  -webkit-box-shadow: @style @c;
  box-shadow:         @style @c;
}
.box-shadow(@style, @alpha: 50%) when (isnumber(@alpha)) {
  .box-shadow(@style, rgba(0, 0, 0, @alpha));
}
.box {
  color: saturate(@base, 5%);
  border-color: lighten(@base, 30%);
  div { .box-shadow(0 0 5px, 30%) }
}

compiles to

.box {
  color: #fe33ac;
  border-color: #fdcdea;
}
.box div {
  -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}

Less can be used on the command line via npm, downloaded as a script file for the browser or used in a wide variety of third party tools. See the Usage section for more detailed information.

Installation

The easiest way to install Less on the server, is via npm, the node.js package manager, as so:

$ npm install -g less

Command-line usage

Once installed, you can invoke the compiler from the command-line, as such:

$ lessc styles.less

This will output the compiled CSS to stdout, you may then redirect it to a file of your choice:

$ lessc styles.less > styles.css

To output minified CSS, simply pass the -x option. If you would like more involved minification, the Clean CSS is also available with the --clean-css option.

To see all the command line options run lessc without parameters.

Usage in Code

You can invoke the compiler from node, as such:

var less = require('less');

less.render('.class { width: (1 + 1) }', function (e, css) {
  console.log(css);
});

which will output

.class {
  width: 2;
}

you may also manually invoke the parser and compiler:

var parser = new(less.Parser);

parser.parse('.class { width: (1 + 1) }', function (err, tree) {
  if (err) {
    return console.error(err)
  }
  console.log(tree.toCSS());
});

Configuration

You may pass some options to the compiler:

var parser = new(less.Parser)({
  paths: ['.', './lib'], // Specify search paths for @import directives
  filename: 'style.less' // Specify a filename, for better error messages
});

parser.parse('.class { width: (1 + 1) }', function (e, tree) {
  tree.toCSS({
    // Minify CSS output
    compress: true
  });
});

Third party tools

See the Usage section for details of other tools.

Command-line With Rhino

Each less.js release contains also rhino-compatible version.

Command line rhino version requires two files:

  • less-rhino-.js - compiler implementation,
  • lessc-rhino-.js - command line support.

Command to run the compiler:

java -jar js.jar -f less-rhino-<version>.js lessc-rhino-<version>.js styles.less styles.css

This will compile styles.less file and save the result to styles.css file. The output file parameter is optional. If it is missing, less will output the result to stdout.

Client-side usage

Using less.js in the browser is great for development, but it's not recommended for production

Client-side is the easiest way to get started and good for developing with Less, but in production, when performance and reliability is important, we recommend pre-compiling using node.js or one of the many third party tools available.

To start off, link your .less stylesheets with the rel attribute set to "stylesheet/less":

<link rel="stylesheet/less" type="text/css" href="styles.less" />

Next, download less.js and include it in a <script></script> tag in the <head> element of your page:

<script src="less.js" type="text/javascript"></script>

Tips

  • Make sure you include your stylesheets before the script.
  • When you link more than one .less stylesheet each of them is compiled independently. So any variables, mixins or namespaces you define in a stylesheet are not accessible in any other.

Browser Options

Options are defined by setting them on a global less object before the <script src="less.js"></script>:

<!-- set options before less.js script -->
<script>
  less = {
    env: "development",
    async: false,
    fileAsync: false,
    poll: 1000,
    functions: {},
    dumpLineNumbers: "comments",
    relativeUrls: false,
    rootpath: ":/a.com/"
  };
</script>
<script src="less.js"></script>

Learn more about Browser Options

Browser downloads

Download Less.js v1.7.4

Download source code

Get the latest Less.js source code by downloading it directly from GitHub.

Clone or fork via GitHub

Fork the project and send us a pull request!

Install with Bower

Install the Less.js project and JavaScript by running the following in the command line:

bower install less

Less CDN

<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/1.7.4/less.min.js"></script>

Less.js is released under the Apache 2 License (though there are plans to dual license it). Copyright 2009-2014, Alexis Sellier and the Less Core Team (see about). Boiled down to smaller chunks, it can be described with the following conditions.

It allows you to:

  • Freely download and use Less.js, in whole or in part, for personal, company internal or commercial purposes
  • Use Less.js in packages or distributions that you create

It forbids you to:

  • Redistribute any piece of Less.js without proper attribution

It requires you to:

  • Include a copy of the license in any redistribution you may make that includes Less.js
  • Provide clear attribution to The Less Core Team for any distributions that include Less.js

It does not require you to:

  • Include the source of Less.js itself, or of any modifications you may have made to it, in any redistribution you may assemble that includes it
  • Submit changes that you make to Less.js back to the Less.js project (though such feedback is encouraged)

The full Less.js license is located in the project repository for more information.


반응형

'Frontend > HTML5' 카테고리의 다른 글

[JS] JSON.parse : Convert this string into array of objects  (0) 2016.08.20
.prependTo()  (0) 2014.08.22
make an Interactive Website 5 coding  (0) 2014.08.22
margin by codecademy  (0) 2014.08.21
ASP.NET MVC4 WEB API  (1) 2013.10.22

Compiling CSS and JavaScript

Bootstrap uses Grunt for its build system, with convenient methods for working with the framework. It's how we compile our code, run tests, and more.

bootstrap은 프레임워크 동작의 편리를 위해 Grunt 의 빌드시스템을 사용한다. 아래는, 우리가 어떻게 코드를 컴파일하고, 테스트와 기타 외작업을 어떻게 하는지 설명한다. 

Installing Grunt

To install Grunt, you must first download and install node.js (which includes npm). npm stands for node packaged modules and is a way to manage development dependencies through node.js.

Then, from the command line:

  1. Install grunt-cli globally with npm install -g grunt-cli.
  2. Navigate to the root /bootstrap/ directory, then run npm install. npm will look at the package.json file and automatically install the necessary local dependencies listed there.

When completed, you'll be able to run the various Grunt commands provided from the command line.


Grunt 설치하기

Grunt 설치하기 위해서는, 먼저 node.js를 다운받는다.(npm이 포함되어 있는). npm은 node packaged modules 과 node.js를 개발 독립적으로 관리하는 방법이다. 

command line에 작성한다 :  
1.  grunt-cli 을 

Available Grunt commands

grunt dist (Just compile CSS and JavaScript)

Regenerates the /dist/ directory with compiled and minified CSS and JavaScript files. As a Bootstrap user, this is normally the command you want.

grunt watch (Watch)

Watches the Less source files and automatically recompiles them to CSS whenever you save a change.

grunt test (Run tests)

Runs JSHint and runs the QUnit tests headlessly in PhantomJS.

grunt (Build absolutely everything and run tests)

Compiles and minifies CSS and JavaScript, builds the documentation website, runs the HTML5 validator against the docs, regenerates the Customizer assets, and more. Usually only necessary if you're hacking on Bootstrap itself.

Troubleshooting

Should you encounter problems with installing dependencies or running Grunt commands, first delete the /node_modules/ directory generated by npm. Then, rerun npm install.

반응형

'Frontend > Bootstrap' 카테고리의 다른 글

GRUNT : The JavaScript Task Runner  (0) 2014.09.02

http://gruntjs.com/

Getting started


Grunt and Grunt plugins are installed and managed via npm, the Node.js package manager. Grunt 0.4.x requires stable Node.js versions >= 0.8.0. Odd version numbers of Node.js are considered unstable development versions.

Before setting up Grunt ensure that your npm is up-to-date by running npm update -g npm (this might requiresudo on certain systems).

Installing the CLI

Using Grunt 0.3? Please see Grunt 0.3 Notes

In order to get started, you'll want to install Grunt's command line interface (CLI) globally. You may need to use sudo (for OSX, *nix, BSD etc) or run your command shell as Administrator (for Windows) to do this.

npm install -g grunt-cli

This will put the grunt command in your system path, allowing it to be run from any directory.

Note that installing grunt-cli does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile. This allows multiple versions of Grunt to be installed on the same machine simultaneously.


1. node.js 설치

2. cmd에서 명령어 입력



How the CLI works

Each time grunt is run, it looks for a locally installed Grunt using node's require() system. Because of this, you can run grunt from any subfolder in your project.

If a locally installed Grunt is found, the CLI loads the local installation of the Grunt library, applies the configuration from your Gruntfile, and executes any tasks you've requested for it to run. To really understand what is happening, read the code


Working with an existing Grunt project

Assuming that the Grunt CLI has been installed and that the project has already been configured with apackage.json and a Gruntfile, it's very easy to start working with Grunt:

  1. Change to the project's root directory.
  2. Install project dependencies with npm install.
  3. Run Grunt with grunt.

That's really all there is to it. Installed Grunt tasks can be listed by running grunt --help but it's usually a good idea to start with the project's documentation.  

Preparing a new Grunt project

A typical setup will involve adding two files to your project: package.json and the Gruntfile.

package.json: This file is used by npm to store metadata for projects published as npm modules. You will list grunt and the Grunt plugins your project needs as devDependencies in this file.

Gruntfile: This file is named Gruntfile.js or Gruntfile.coffee and is used to configure or define tasks and load Grunt plugins. When this documentation mentions a Gruntfile it is talking about a file, which is either a Gruntfile.js or a Gruntfile.coffee.

package.json

The package.json file belongs in the root directory of your project, next to the Gruntfile, and should be committed with your project source. Running npm install in the same folder as a package.json file will install the correct version of each dependency listed therein.

There are a few ways to create a package.json file for your project:

  • Most grunt-init templates will automatically create a project-specific package.json file.
  • The npm init command will create a basic package.json file.
  • Start with the example below, and expand as needed, following this specification.
{
  "name": "my-project-name",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.5",
    "grunt-contrib-jshint": "~0.10.0",
    "grunt-contrib-nodeunit": "~0.4.1",
    "grunt-contrib-uglify": "~0.5.0"
  }
}

Installing Grunt and gruntplugins

The easiest way to add Grunt and gruntplugins to an existing package.json is with the commandnpm install <module> --save-dev. Not only will this install <module> locally, but it will automatically be added to the devDependencies section, using a tilde version range.

For example, this will install the latest version of Grunt in your project folder, adding it to your devDependencies:

npm install grunt --save-dev

The same can be done for gruntplugins and other node modules. Be sure to commit the updatedpackage.json file with your project when you're done!


프로젝트 파일의 root 지점으로 이동한 뒤, Grunt를 설치한다. 



그럼, node_modules 이라는 폴더가 생성되고, 그 안에 생성된 Grunt라는 폴더에는 다음과 같은 파일들이 함께 생성된다.

The Gruntfile

The Gruntfile.js or Gruntfile.coffee file is a valid JavaScript or CoffeeScript file that belongs in the root directory of your project, next to the package.json file, and should be committed with your project source.

Gruntfile is comprised of the following parts:

  • The "wrapper" function
  • Project and task configuration
  • Loading Grunt plugins and tasks
  • Custom tasks

An example Gruntfile

In the following Gruntfile, project metadata is imported into the Grunt config from the project'spackage.json file and the grunt-contrib-uglify plugin's uglify task is configured to minify a source file and generate a banner comment dynamically using that metadata. When grunt is run on the command line, theuglify task will be run by default.

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
      },
      build: {
        src: 'src/<%= pkg.name %>.js',
        dest: 'build/<%= pkg.name %>.min.js'
      }
    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Default task(s).
  grunt.registerTask('default', ['uglify']);

};

Now that you've seen the whole Gruntfile, let's look at its component parts.

The "wrapper" function

Every Gruntfile (and gruntplugin) uses this basic format, and all of your Grunt code must be specified inside this function:

module.exports = function(grunt) {
  // Do grunt-related things in here
};

Project and task configuration

Most Grunt tasks rely on configuration data defined in an object passed to the grunt.initConfig method.

In this example, grunt.file.readJSON('package.json') imports the JSON metadata stored in package.jsoninto the grunt config. Because <% %> template strings may reference any config properties, configuration data like filepaths and file lists may be specified this way to reduce repetition.

You may store any arbitrary data inside of the configuration object, and as long as it doesn't conflict with properties your tasks require, it will be otherwise ignored. Also, because this is JavaScript, you're not limited to JSON; you may use any valid JS here. You can even programmatically generate the configuration if necessary.

Like most tasks, the grunt-contrib-uglify plugin's uglify task expects its configuration to be specified in a property of the same name. Here, the banner option is specified, along with a single uglify target namedbuild that minifies a single source file to a single destination file.

// Project configuration.
grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),
  uglify: {
    options: {
      banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
    },
    build: {
      src: 'src/<%= pkg.name %>.js',
      dest: 'build/<%= pkg.name %>.min.js'
    }
  }
});

Loading Grunt plugins and tasks

Many commonly used tasks like concatenationminification and linting are available as grunt plugins. As long as a plugin is specified in package.json as a dependency, and has been installed via npm install, it may be enabled inside your Gruntfile with a simple command:

// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');

Note: the grunt --help command will list all available tasks.

Custom tasks

You can configure Grunt to run one or more tasks by default by defining a default task. In the following example, running grunt at the command line without specifying a task will run the uglify task. This is functionally the same as explicitly running grunt uglify or even grunt default. Any number of tasks (with or without arguments) may be specified in the array.

// Default task(s).
grunt.registerTask('default', ['uglify']);

If your project requires tasks not provided by a Grunt plugin, you may define custom tasks right inside theGruntfile. For example, this Gruntfile defines a completely custom default task that doesn't even utilize task configuration:

module.exports = function(grunt) {

  // A very basic default task.
  grunt.registerTask('default', 'Log some stuff.', function() {
    grunt.log.write('Logging some stuff...').ok();
  });

};

Custom project-specific tasks don't need to be defined in the Gruntfile; they may be defined in external.js files and loaded via the grunt.loadTasks method.

Further Reading

  • The Installing grunt guide has detailed information about installing specific, production or in-development, versions of Grunt and grunt-cli.
  • The Configuring Tasks guide has an in-depth explanation on how to configure tasks, targets, options and files inside the Gruntfile, along with an explanation of templates, globbing patterns and importing external data.
  • The Creating Tasks guide lists the differences between the types of Grunt tasks and shows a number of sample tasks and configurations.
  • For more information about writing custom tasks or Grunt plugins, check out the developer documentation.

http://gruntjs.com/getting-started

반응형

'Frontend > Bootstrap' 카테고리의 다른 글

Compiling CSS and JavaScript  (0) 2014.09.02




Create a new li element  : $('<li>');

Select the h2 element nested insind the <div class="article"> ... </div> element. : $('.article h2');

Text

 





반응형

'Frontend > HTML5' 카테고리의 다른 글

[JS] JSON.parse : Convert this string into array of objects  (0) 2016.08.20
Get Start Less  (0) 2014.09.02
make an Interactive Website 5 coding  (0) 2014.08.22
margin by codecademy  (0) 2014.08.21
ASP.NET MVC4 WEB API  (1) 2013.10.22
Preview

Let's use jQuery to build a news reader.

  • The file index.html contains the page structure and content
  • The file style.css has the styling for the page
  • Click on the first article.
  • Use the n keyboard shortcut to go to the next article.
  • Then use the o keyboard shortcut to open the article description.
  • If you have issues, check out the hint!
  • Click Save & Submit Code to get started!
  1. Click on the first article.
  2. Use the n keyboard shortcut to go to the next article.
  3. Then use the o keyboard shortcut to open the article description.
  4. If you have issues, check out the hint!
  5. Click Save & Submit Code to get started!
?
Hint

If the keyboard shortcuts do not work, look at your code and see if you have a bunch of n's and o's which should not be there!

Delete those n's and o's. Then make sure you click on an article before you press the n's and o's. Hopefully it works now!



Program skeleton

The index.html file has two scriptelements right before the closing </body>tag:

  • The first script loads jQuery.
  • The second script loads app.js. The fileapp.js is where we'll write jQuery code for our news reader.


var main = function() {

};


$(document).ready(main);





























반응형

'Frontend > HTML5' 카테고리의 다른 글

Get Start Less  (0) 2014.09.02
.prependTo()  (0) 2014.08.22
margin by codecademy  (0) 2014.08.21
ASP.NET MVC4 WEB API  (1) 2013.10.22
Javascript / text / cs 연결할 때  (59) 2013.08.30




Events

User interactions with a web page are called events.

For example, when you click the Like button to the right, the browser announces that a click event has occurred.



Event Handlers
We can write a function that specifies what to do when an event occurs. This function is called anevent handler.


When a user clicks the .like-button element, the event handler toggles the "active" class. This alternates the button between the normal gray view and the selected blue view.

.click()

In the page to the right, click the three share buttons at the top of the page.

One common user event is the click event. A click event occurs when a user clicks on an HTML element.

The .click() method attaches an event handler to an HTML element so that it can respond to a click event.

$('.social li') selects each share button at the top of the web page.

The .click() method attaches an event handler to each button.

The event handler adds the CSS class .active, which changes the button's background-color to red. We use $(this) to refer to the HTML element that was clicked on. We can now operate on this element using .toggleClass().

Putting it all together, when you click on a share button at the top of the page, a click event is triggered by the browser.

When the click event occurs, the .click() method runs the event handler. In this code, the event handler changes the button color to red.



.keypress()

In the page to the right, click inside the page, and then press any letter or number key.

Another common user event is the keypress event. A keypress event occurs when a user types a key on the keyboard.

The .keypress() method attaches an event handler to an HTML element so that it can respond to a keypress event.


$(document) selects the whole web page.The .keypress() method attaches an event handler to document

When any keyboard key is pressed, the event handler toggles the dropdown menu.


Putting it all together, when you press any keyboard key, a keypress event is triggered by the browser.

When the keypress event occurs, the .keypress()method runs the event handler.

Here, the event handler toggles the dropdown menu. Putting it all together, when you press any keyboard key, a keypress event is triggered by the browser.

When the keypress event occurs, the .keypress()method runs the event handler.

Here, the event handler toggles the dropdown menu.

event

In the page to the right, click inside the page, and then press the m key.

Triggering a keypress event handler when any key is typed isn't particularly useful. For more control, we can use the event object.

The event object contains more information about an event, such as which mouse button was clicked or which key was pressed.

$(document) selects the whole web page, and the.keypress() method attaches an event handler todocument.The event handler takes event as a parameter. event.which contains which key was pressed. Keyboard keys are identified by key codes. The m key is identified by the key code 109.









반응형

'Frontend' 카테고리의 다른 글

make an Interactive Website 3 JavaScript  (0) 2014.08.22
make an Interactive Website 2 Jquery coding  (0) 2014.08.22
make an Interactive Website 1  (0) 2014.08.21
make website 3 coding  (0) 2014.08.21
make web site 2 bootstrap  (0) 2014.08.21

JavaScript

In order to make interactive web pages with jQuery, it's useful to know a few things about JavaScript.

JavaScript is a programming language that jQuery is written in, and knowing JavaScript will be helpful for understanding and writing your code.

The next cards will cover a few fundamental JavaScript concepts.


Variables

Variables store data so that they can be used later on in the program.  The keyword var creates a new variable namedcounterThe value 140 is stored in counterThe statement ends with a semicolon to tell the computer that the statement has ended.

Strings


Comparisons

It's possible to compare variables using comparisons.

  • > - Greater than

  • < - Less than

  • >= Greater than or equal to

  • <= Less than or equal to

  • === Equal to score1 === score2;

  • !== Not equal to


Functions

A function is run by calling its name and giving it input values.












반응형

'Frontend' 카테고리의 다른 글

make an Interactive Website 4 Event  (0) 2014.08.22
make an Interactive Website 2 Jquery coding  (0) 2014.08.22
make an Interactive Website 1  (0) 2014.08.21
make website 3 coding  (0) 2014.08.21
make web site 2 bootstrap  (0) 2014.08.21
Preview

We are going to use jQuery to create a menu that slides out from the left side.

  • The file index.html contains the page structure and content.
  • The file style.css has the styling for the page.
  • The file app.js has JavaScript and jQuery code. This code makes the menu interactive.

  1. Click on the menu icon. The menu displays by pushing the page's body over to the right.
  2. Then click on the X icon. The menu closes by pulling the body back to where it was.
  3. Click Save & Submit Code to get started!
Program skeleton

The index.html file has two scriptelements right before the closing </body>tag:

  • The first script loads jQuery.
  • The second script loads app.js. The fileapp.js is where we'll write out code for the Uber menu.

Let's start by setting up the basic skeleton for JavaScript programs.

  1. Inside the app.js file, use the keywordvar and create a function called main.
  2. Leave the function's code block empty.
  3. Use jQuery to run the main function once the web page has fully loaded.
  4. See the hint if you're stuck!


/*Inside the app.js file, use the keyword var and create a function called main.*/

var main = function(){
    
};

/*Use jQuery to run the main function once the web page has fully loaded.*/
$(document).ready(main);
 
Select an element

What does this skeleton do?

  1. The main function is where we'll write our program.
  2. The $(document).ready runs the mainfunction as soon as the HTML document has loaded in the browser.

Let's start filling out the main function. Here, we'll select an HTML element in order to operate on it. jQuery lets us select HTML elements using CSS selectors.

  1. In app.js, find the main function.
  2. Inside the main function, use jQuery to select the class 'icon-menu'.  $('.icon-menu');
  3. Small hint: jQuery is all about the dollars! And to select a class, use a period (ie. full stop).
  1. Start with a $( ) to tell the computer we're using jQuery.
  2. To use CSS to select the class 'icon-menu', we type in '.icon-menu'.
Respond to a click

We have just used jQuery to select the'icon-menu' class using $('.icon-menu')

Now we want to respond to user action.

Specifically we want to respond to a user clicking on this '.icon-menu' HTML element.

After $('.icon-menu'), add the .click()method.


Open the menu

We now have code that says something will happen when the user clicks on theicon-menu HTML element. But what will happen?!

Clicking on the menu icon should open the menu.

  1. Add a function inside the .click()method.
  2. Select the 'menu' class and animate it.
  3. Right now, the menu is 285px past the left edge of the screen. That's why it is not visible! Inside the animate method:

    a move it 0px to the left
    b. make this happen over 200 milliseconds.

  4. We now want to push the rest of the page to the left 285px. Use jQuery to select the body HTML element, animate it, and move it left 285px over 200 milliseconds.

Close the menu

Once the menu is open, we need a way to close it. Let's adapt the three steps we used to open the menu in order to close the menu.

  1. Use jQuery to select the '.icon-close'element.
  2. Add the .click() method.
  3. When the '.icon-close' element is clicked, use .animate() to change the leftoffset of the menu to -285px, and the leftoffset of the body to 0px. Both are done over 200 milliseconds.
  4. Click on the menu icon and the X to see if your code works!




반응형

'Frontend' 카테고리의 다른 글

make an Interactive Website 4 Event  (0) 2014.08.22
make an Interactive Website 3 JavaScript  (0) 2014.08.22
make an Interactive Website 1  (0) 2014.08.21
make website 3 coding  (0) 2014.08.21
make web site 2 bootstrap  (0) 2014.08.21

Make an Interactive Website

Build the Flipboard home page and learn how to add interactivity to your website.

Introduction

Web pages made with HTML and CSS display static content. They don't respond to user actions like clicking a mouse or typing a key.

JavaScript and jQuery are used to make web pages interactive.

  • JavaScript is a programming language used to create web pages that change in response to user actions.

  • jQuery is a collection of prewritten JavaScript code that lets us easily create interactive effects on our site.

Click on More and the navigation arrows in the web page to the right.


Your first program

Click on Flipboard at the top of the web page to the right. The web page has a dropdown menu which shows and hides when you click Flipboard.

This interaction is made with JavaScript and jQuery.


Here's what the web page's HTML looks like.

  • To include CSS files in HTML we used the linkelement.

  • Similarly, to include JavaScript files in HTML, we use the script element.

  • To include CSS files in HTML, we use the linkelement. The link element tells the browser where to find a CSS file.

  • Similarly, to include JavaScript files in HTML, we use the script element.

    The script element tells the browser where to find a JavaScript file. It has an attribute inside the opening <script> tag named src, which has the address of the JavaScript file.

  • The first script loads in jQuery.

  • The second script loads in app.js. This is where the code for the dropdown menu program lives.



When you click on Flipboard, the dropdown menu shows up but doesn't go away. Change the jQuery method from $(".dropdown-menu").show(); to $(".dropdown-menu").toggle(); to toggle the dropdown menu. Then click on Flipboard once to make the menu appear, and again to make it disappear.

$(document).ready()

The $(document).ready() waits for the HTML document to load completely before running the main() function.

This is important because JavaScript should only run after the web page has loaded completely in the browser - otherwise there wouldn't be any HTML elements to add interactivity to.








반응형

'Frontend' 카테고리의 다른 글

make an Interactive Website 3 JavaScript  (0) 2014.08.22
make an Interactive Website 2 Jquery coding  (0) 2014.08.22
make website 3 coding  (0) 2014.08.21
make web site 2 bootstrap  (0) 2014.08.21
make web site 1 by codecademy  (0) 2014.08.21
Navigation

The navigation menus are made up of two ulelements. In each ul, the li elements display on new lines because they are block elements. Let's style the li elements so that they display on the same line. This can be done with thedisplay property.

Jumbotron

Nice! The menu items inside each ul now are now inline elements. [We'll see how to move the two uls to display on the same line in the next section.]

Next let's change the position of the text inside the large feature. Currently the text is positioned at the very top of the large feature. Let's move the text down so that its more in the middle of the large feature. This can be done with the position property.

In index.html, the <div class="jumbotron">..</div> groups elements that are part of the large feature section of the web page. Inside<div class="jumbotron">..</div> is the <divclass="container">..</div> which has the text 

Adding Bootstrap

Bootstrap is a CSS framework used to build pages faster. Bootstrap provides a lot of useful CSS out of the box. Check out the Bootstrap file at "http://s3.amazonaws.com/codecademy-content/courses/ltp/css/bootstrap.css" - it has CSS properties and values, many of which you've seen already, to style HTML.

What just happened?

Nicely done! What's going on here?

The order of the CSS files matter.
1. The browser first sees shift.css, and makes the Shift font available to use in the page
2. Next the browser sees bootstrap.css, and applies those styles to the page.
3. Then the browser sees main.css, and applies those custom styles to the page. The custom styles override the Bootstrap styles.

The order of the CSS files tell the browser that your styles in main.css are more important than the styles in bootstrap.css, so the final page that loads is the customized web page.


Navigation

In index.html inside <div class="nav">..</div>, the navigation menus are made up of two ul elements. So far we've styled the lielements to display on the same line. Now let's style the ul elements to show up on the same line too.

Bootstrap provides the .pull-left class to left-align an element, and the .pull-rightclass to right-align an element. Let's use these classes to finish styling the navigation bar.


Learn More: Grid

Looking good! Both menus now show up on the same line, and the navigation bar is complete.

Next, let's use Bootstrap's grid to arrange the three pieces of supporting content inside the<div class="learn-more">..</div> section. Here's how to use Bootstrap's grid.

<div class="container">

  <div class="row">
    <div class="col-md-4">
      ...
    </div>

    <div class="col-md-4">
      ...
    </div>

    <div class="col-md-4">
      ...
    </div>

  </div>
</div>
  1. First inside <div class="container">..</div>, there is a row defined by <div class="row">..</div>
  2. A row is made up of columns, so inside<div class="row">..</div>, there are three columns each defined by <div class="col-md-4">

Why is the .col-md-4 class being used? Remember that Bootstrap's grid is 12 columns. Therefore, to create three equal-sized columns, they each need to span 4 grid columns.



Neighborhood Guides: Grid

Excellent! Using Bootstrap's grid, you arranged the three pieces of supporting content into a three-column layout.

Let's use Bootstrap's grid again to create another section on the page. This section will contain a grid of images.

Neighborhood Guides: Images 1

Nice work! Next let's add some images inside the columns.

Bootstrap provides the ".thumbnail" class to easily display grids of images. An img element is wrapped in a div element with the class "thumbnail".

<div class="row">
  <div class="col-md-4">
     <img src="http://goo.gl/0sX3jq" >
  </div>

  <div class="col-md-4">
    <div class="thumbnail">
      <img src="http://goo.gl/Av1pac" >
    </div>
    <div class="thumbnail">
      <img src="http://goo.gl/vw43v1">
    </div>
  </div>

  <div class="col-md-4">
    <div class="thumbnail">
      <img src="http://goo.gl/0Kd7UO" >
    </div>
  </div>

</div>


Neighborhood Guides: Final touches

Excellent! Using Bootstrap's grid, we created a brand new section on the web page displaying a grid of images.

Let's finish up this section with a few custom CSS styles.

In main.css, make a new CSS rule that selects.neighborhood-guides

  1. Set the background-color to #efefef
  2. Set border-bottom to 1px solid #dbdbdb

Make a second CSS rule that selects the h2element inside .neighborhood-guides

  1. Set the color to #393c3d
  2. Set the font-size to 24px

Make a third CSS rule that selects the pelement inside .neighborhood-guides

  1. Set the font-size to 15px
  2. Set the margin-bottom to 13px


Navigation

You've done a lot so far. You learned about HTML, CSS, and Bootstrap, and created the Airbnb home page from scratch.

Now it's time to make it your own. Let's start with the navigation bar and work our way down the page.



반응형

'Frontend' 카테고리의 다른 글

make an Interactive Website 3 JavaScript  (0) 2014.08.22
make an Interactive Website 2 Jquery coding  (0) 2014.08.22
make an Interactive Website 1  (0) 2014.08.21
make web site 2 bootstrap  (0) 2014.08.21
make web site 1 by codecademy  (0) 2014.08.21



Introduction

We saw how to use CSS rules to control the style and layout of a page.

Bootstrap is a collection of prewritten CSS rules used to build web pages faster. Bootstrap provides styles out of the box for several common components on a web page, such as grid layouts, navigation, showcases, and much more.

Let's see how to get started using Bootstrap in your web page.




The grid

grid is a useful way to create page layouts. Rather than create layouts from scratch, HTML elements can be aligned to a grid in different ways to create custom layouts.

Bootstrap comes with a grid that is made up of 12 equal-sized columns. HTML elements are arranged to span different numbers of columns in order to create custom page layouts.



Bootstrap's grid is made up of 12 equal-sized columns. Each piece of content is aligned to this grid by specifying the number of columns to span.

The code to the right uses Bootstrap's grid to create a layout with two pieces of content.

Here each piece of content spans six columns, so it uses the .col-md-6 class.

Both columns are wrapped in a .row class to create a horizontal group.


<ul class="nav nav-tabs">

<li><a href="#">Primary</a></li>

<li class="active"><a href="#">Social</a></li>

<li><a href="#">Promotions</a></li>

<li><a href="#">Updates</a></li>

</ul>


<ul class="nav nav-pills">

<li><a href="#">Primary</a></li>

<li class="active"><a href="#">Social</a></li>

<li><a href="#">Promotions</a></li>

<li><a href="#">Updates</a></li>

</ul>



Summary

By adding Bootstrap classes to your HTML elements, you can make use of Bootstrap's CSS to build your page faster. This lets you quickly set up the basic styles and layout so that you can get to the more interesting aspects of your page's design.

Bootstrap provides CSS for many more web components. Check out this site to see how else you can use Bootstrap to style your HTML elements!


반응형

'Frontend' 카테고리의 다른 글

make an Interactive Website 3 JavaScript  (0) 2014.08.22
make an Interactive Website 2 Jquery coding  (0) 2014.08.22
make an Interactive Website 1  (0) 2014.08.21
make website 3 coding  (0) 2014.08.21
make web site 1 by codecademy  (0) 2014.08.21

+ Recent posts