Category Archives: javascript

Side menu with jQuery.

This side menu is a very simple example with HTML5, CSS and jQuery.
The result is this:

You can see the source code:

Posted in All, HTML 5, javascript, Programming. Tagged with , , , .

Random lines with jQuery.

This is a complex tutorial about HTML5, jQuery and javascript.
The result of this tutorial will be a text and one canvas with random animated lines.
The result is this animated line into html5 file (also you can see my codepen example) :
free-tutorials
Because I used jQuery , first line of code into head section was:

To see the result: the text and canvas I used into body section this tags:

The next step is to have a style into my html5 file, so I put this code into head section:

Next steps:

  • select canvas for draw ( I used c variable );
  • make a random points into canvas ( I used a function);
  • make points and lines ( I used b function);
  • make create, animate and line function object as a combination of a prototype;

JavaScript allows you to use a Function object as a combination of a prototype to use for the new object and a constructor function to invoke.
The event.pageX property returns the position of the mouse pointer, relative to the left edge of the document.
Let’s see now the full source code:

Posted in All, HTML 5, javascript, Programming. Tagged with , , , .

JavaScript – geolocation.

This is a simple java script to take the geolocation and show it on webpage.
The example start with a default HTML 5 page and the part from tags scripts get the geolocation and using innerHTML is show on webpage.
To see the location then is need to use this: navigator.geolocation.getCurrentPosition.

Posted in All, HTML 5, javascript. Tagged with , , , , , .

JavaScript – toggle button example.

Is a simple example about toggle button.
You need to start with input button and then get the state of this

Then add the type and id and style.
You can remove the text-indent: -9999px; and Toggle button if you don’t want to see text to this toggle button.
Let’s see the full source code and how is working.
The part after hr tag with button and paragraph tag id=output is just for tested the toggle button.
You can make a html file and put this source code to test it.

Posted in All, javascript, Programming. Tagged with , , , .

WebRTC – one simple first example webcam – part 002.

As you know already the WebRTC allow us provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs.The WebRTC components have been optimized to best serve this purpose.
You also need to put tunneling WebRTC over TCP because that tunneling it matters.
But today I will show you just a simple first example about webcam and WebRTC.
The HTML5 file is very simple:

You need to have a video tag with id for identification tag named “player”. You can put anything you like into areas of id’s, but that will reflect the part of javascript.
The autoplay segment code will start the running part of video tag.
You see the HTML file come with two references to files: webcam.css and webcam.js.
The webcam.css will allow you to add a more stylized part of HTML file and that will reflect the output.
The webcam.js will allow you to make WebRTC communications over internet…
Let’s start with css file:

The body and player parts are used to make changes into HTML output.
The body is a default for HTML tag body and for id’s is used # and the named id’s.
For example: If you named your tags like word, next, pass, all the id’s will be #word, #next, #pass, #all.
Anyway. this allow you just stylized your HTML output.
To have a real communication then you need javascript.
This javascript can be part of HTML files into two ways.
First is to put into HTML5 and that has some limits.
The next step is to use another javascript that is loaded by HTML file.
My example uses the best HTML format HTML5 encoding.
You can see into my example the HTML load the webcam.js script into area of head tag.
Let’s see the javascript file:

I create an object named mediaOptions. The objects can be also created like that format: var car = new Object();
I used achieved with: var mediaOptions = { audio: false, video: true };
This variable object will can be started or not.
This is part of two if statements and will return the getUserMedia function.
The next step is to give all infos and data to make all running:
navigator.getUserMedia(mediaOptions, success, function(e) {
console.log(e);
});

function success(stream){
var video = document.querySelector(“#player”);
video.src = window.URL.createObjectURL(stream);
}

The MediaStream object that contains the media stream is allow by success and the callback of getUserMedia.
That function – success put into video tag the output of your webcam.
Your browser allow you to see the webcam by running this: HTML5, javascript and css.
If you read my old webrtc-first-steps-part-001 example you will see is more complex.
The main reason was to see the global area and then to understand how simple is to write code.
Most part of my previous tutorial are also very important parts.
That will increase the strength into areas. This source code is also good, but not great.
To have a good secure then you need to use more … (like tunneling).

Posted in All, HTML 5, javascript, web, WebRTC. Tagged with , , , , , .