Javascript – Objects

Javascript – Objects

In Javascript, objects are arrays where indexes are the property names. You can declare an object: var person = {}; The properties are separated with ‘,’ and the key/value for its property is separated with ‘:’. The property name can have single quotes, double quotes or nothing. name:”Kronos” ‘name’:”Kronos” “name”: “Kronos” You can access a property using ‘.’. If the property name starts with a number or is a reserved word then you have to use ‘[]’ and quotes: person.name = “Kronos”; person[‘1name’] = “Kronos”; An object can contain another…

Javascript – Objects Read More

Javascript – Geolocation API

Javascript – Geolocation API

With Geolocation API, the user can provide their location to web sites. You can access it with the navigation.geolocation object. Check if the browser supports the API: To get the current position: If you want to follow the location in case it changes then you can use the watchPosition() method. It also returns a unique id which you can use to identify the requested position. Javascript – Geolocation API

Javascript – Geolocation API Read More

Javascript – Audio, Video & WebCam API

Javascript – Audio, Video & WebCam API

HTML Audio and Video elements have methods, properties and events that can be changed/called from Javascript. Properties currentSrc currentTime videoWidth videoHeight error muted seeking volume height width controls Read-only propertied played startTime duration ended paused seekable Methods play pause load canPlayType Events play pause progress error timeupdate ended abort empty emptied waiting loadedmetadata If you want to access the WebCam you need to use the getUserMedia API Javascript – Audio, Video & WebCam API

Javascript – Audio, Video & WebCam API Read More

Javascript – Canvas

Javascript – Canvas

Canvas is a transparent HTML element that is used for drawing and animation. To draw or animate on the canvas we first need to create the HTML element. Then in Javascript, we need to get the canvas reference, create a context object and then we can draw on it. with save() function you save/push the context setting to the stack and with the restore() function you get/pop the last setting from the stack. Animating If you want to animate object on the canvas there is an animation loop: Clear the…

Javascript – Canvas Read More

Javascript – Create, move and remove HTML elements

Javascript – Create, move and remove HTML elements

Create an HTML element To create an HTML element, first you must use createElement(). Then set any values and the style. The last step is to add the created element in the DOM using append(), appendChild(), insertBefore() or innerHTML property. Move an HTML element If you want to move an HTML element you should use append() and appendChild(). This can only happen if you get the element somewhere else in the document. Remove an HTML element You can remove an HTML element using the removeChild(element) method or the innerHTML property…

Javascript – Create, move and remove HTML elements Read More