Code Monkey home page Code Monkey logo

javascript-bones's Introduction

Javascript-Bones

A repo to understand few complex topics in js Structure - Behaviour - Presentation HTML - JS - CSS

Some DOM Basics

1 Select & Manipulate:

Select

getElementById getElementsByClassName getElementsByTagName querySelector

document.querySelector('hi');

Manipulate

var h1 = document.querySelector('hi');
h1.style.color = 'pink';

Eg 1: Every second change the color of body until 1 minute we can take help of setInterval in js

var body = document.querySelector('body');
var isBlue = false;
var time = 0;
var Animator = setInterval(function(){
	time+=1;
	if(time === 60){
		clearInterval(Animator);
	}
	if(isBlue){
		body.style.background = "white";
	} else {
		body.style.background = "grey";
	}
	isBlue = !isBlue;
}, 100); 

Manipulate

  • a) changing an element style
  • b) adding/removing classes
  • c) changing the content of a tag
  • d) changing attributes(src, href, etc)
a) changing an element style

var tag = document.getElementById('highlight'); tag.style.color = 'blue'; tag.style.border = '10px solid red'; tag.style.fontSize = '70px'; tag.style.background = 'yellow'; tag.style.marginTop = '200px';

say if we have a class

.some-class{
 color: blue;
 fontSize: 76px;
}
tag.classList.add('some-class');
tag.classList.remove('some-class');
tag.classList.toggle('some-class');

Eg2: Move a box from left to right by creating an animating effect

var body = document.querySelector('body');
var isBlue = false;
var time = 0;

var box = document.createElement('div');
box.style.height="30px";
box.style.width="30px";
box.style.background="orange";
box.style.position = "relative";

body.append(box);
var time = 0;
function getValueinpixels(pix){
  return Number(pix.slice(0, pix.length-2));
}
var animate = setInterval(function(){
	if(time === 60){
		clearInterval(animate);
	}
	box.style.left = getValueinpixels(box.style.left)+10+'px';
	console.log('---', getValueinpixels(box.style.left), '---');
time+=1;
}, 100);

CSS

Flex Box

Container Properties

  • flex-direction
  • justify-content
  • flex-wrap
  • align-items
  • align-content

Flex Item Properties

  • order
  • flex
  • flex-grow
  • flex-shrink
  • align-self

javascript-bones's People

Contributors

venkatachadalawada avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.