Category Archives: javascript

JavaScript – clickable area example.

This example use a simple way to see the mouse position.
The area where you make click with the mouse.
You have two variables: mouseXPos, mouseYPos.
The function(e) take the mouse position and show the result.
<!DOCTYPE html>
<title>Title of the document</title>
<script src=”../js/jquery-2.2.0.js”></script>
<style type=”text/css”>
html, body { text-align: center; }
div {
background: grey;
cursor: pointer;
display: inline-block;
font-size: 3em;
margin: 2em auto;
padding: 2em;
p {
background: grey;
padding: 1em;
<script type=”text/javascript”>
window.mouseXPos = 0;
window.mouseYPos = 0;

$(function() {
$(document).on(‘click’, ‘#clickable_area’, function(e) {
mouseXPos = e.pageX;
mouseYPos = e.pageY;

$(‘p’).text(mouseXPos + ‘:’ + mouseYPos);
<div id= “clickable_area”>a click area</div>

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

Make clock with animated SVG file.

This tutorial will be very simple and come with two files.
One of this file was a html file and also one SVG animated file.
First file just put the SVG file into html file, see:

<title>Clock with SVG –</title>
<embed src=”clock.svg” width=”150″ height=”150″ />

The next file was a file with svg tags, like type of svg file , tags to make the circles and ticks also one script to take the time and show the clock time.
Take a look and you will understand how is working.

<?xml version=”1.0″ encoding=”UTF-8″?>
<svg xmlns=””
width=”100%” height=”100%”
viewBox=”0 0 150 150″ version=”1.1″>

<!–  (c) –>

<g id=”clock” style=”fill: rgb(10%,10%,10%)” transform=”translate(75,75) rotate(-90)”>
<g id=”fata_ceas”>
<circle style=”fill: rgb(15%,15%,15%)” cx=”0″ cy=”0″ r=”70″    />
<circle style=”fill: rgb(30%,70%,90%)” cx=”0″ cy=”0″ r=”65″/>
<circle style=”fill: rgb(70%,70%,70%)” cx=”0″ cy=”0″ r=”60″/>

<g id=”minutare”>
<rect transform=”rotate( 0)” x=”42.5″ y=”-2″ width=”17.5″ height=”4″/>
<rect transform=”rotate( 6)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(12)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(18)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(24)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(30)” x=”45″   y=”-2″ width=”15″   height=”4″/>
<rect transform=”rotate(36)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(42)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(48)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(54)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(60)” x=”45″   y=”-2″ width=”15″   height=”4″/>
<rect transform=”rotate(66)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(72)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(78)” x=”55″   y=”-1″ width=”5″    height=”2″/>
<rect transform=”rotate(84)” x=”55″   y=”-1″ width=”5″    height=”2″/>

<use xlink:href=”#minutare” transform=”rotate(90)”/>
<use xlink:href=”#minutare” transform=”rotate(180)”/>
<use xlink:href=”#minutare” transform=”rotate(270)”/>

<path id=”hours”   d=”M -15 3.5 37.5 3.5 41 0 37.5 -3.5 -15 -3.5 Z” />
<path id=”minutes” d=”M -15 2   55   2   57 0 55   -2   -15 -2   Z” />
var minutehand = document.getElementById (“minutes”);
var hourhand   = document.getElementById (“hours”);

function updateTime () {
var date = new Date ();
var m = date.getMinutes() * 6 + date.getSeconds() / 10;
var h = date.getHours() * 30 + m / 12;

minutehand.setAttribute (“transform”, “rotate(” + m + “)”);
hourhand.setAttribute   (“transform”, “rotate(” + h + “)”);
window.setTimeout (“updateTime()”, 1000);

updateTime ();

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

Random circles with jQuery.

If you don’t understand all of my tutorials then you need to take a look of this tutorial.
You need a default html5 template. Into this html5 will add the css – Cascading Style Sheets, link to jQuery, and our javascript.
You need to include into project the jQuery. Download the jQuery from internet and put into same folder with your html5 file.

You need to put css for each html tag and will do that with:

Into body tag will put the window canvas and the javascript to draw into canvas.
First after body tag will come with:

The next step is to draw into canvas with javascript by using canvas into 2D – dimensions:

The basic issue is to fill the webpage with circles. All circles will be make random with this parameters: color, x, y, radius, orbit and speed.

All circles will be make like one array:

You need also to make all vars and this functions: r256, reset, resize, render.
When you used render function then you need to put also this function: requestAnimationFrame(render);
The r256 is one function for random up to 256. Is used most for colors ( red – green – blue ) range.
The reset function will make 160 circles.
The resize will resize the canvas with circles.
The render function will clean, fill and move all circles and then will make another frame for us with requestAnimationFrame function.
All variables and math functions is used for draw and show the canvas, circles, move and color stuff.
I don’t want to explain this steps because is very simple and also the goal is to understand the basic structure of the script.
Let’s see the full source code.

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

Rate this with jQuery.

The main index.html file come with this source code:

<!doctype html>
<meta charset=”utf-8″>
<title>Emoticons – rate this …</title>
<link href=”ratethis.css” rel=”stylesheet” type=”text/css” />
<script src=”jquery-2.2.0.js”></script>
<script src=”ratethis.js”></script>
<input type=”hidden” value=”amo” class=”rate_it”/>
$(‘.rate_it’).ratethis(); </script>

The ratethis.css come with this source code:

.ratethis  { display: none;padding-bottom:8px;padding-top:8px;padding-right: 8px;
padding-left: 0px;box-sizing: border-box;background: white;color: white;position: absolute;
width: auto;height: 65px;line-height: 25px;border-radius: 50px;transition: .25sease-in-out;color:black;
border: 1px solid #eee;
-webkit-box-shadow: 4px 4px 21px -9px rgba(0,0,0,0.75);
-moz-box-shadow: 4px 4px 21px -9px rgba(0,0,0,0.75);
box-shadow: 4px 4px 21px -9px rgba(0,0,0,0.75);}

.ratethis  div{margin-left: 8px;float: left;width: 48px; height: 48px; cursor: pointer; transition: all 0.2s ease;}
.selectorFace{margin-left: 8px;float: left;width: 48px; height: 48px; cursor: pointer; transition: all 0.2s ease;}
.ratethis  div:hover{ -webkit-transform:scale(1.25);-moz-transform:scale(1.25);-ms-transform:scale(1.25);-o-transform:scale(1.25);transform:scale(1.25);}

.molesto{ margin-left: 8px;float: left;width: 48px; height: 48px; background: url(test.png) 0 0; }
.asusta{background: url(test.png) 0 -48px; }
.divierte{background: url(test.png) 0 -96px; }
.gusta{background: url(test.png) 0 -144px; }
.amo{background: url(test.png) 0 -192px; }
.triste{background: url(test.png) 0 -240px; }
.asombro{background: url(test.png) 0 -288px; }
.alegre{background: url(test.png) 0 -336px; }

.MessageText{display:none;position:absolute;border:1px solid #333;background-color:#161616;
border-radius:5px;padding:3px;color:#fff;font-family: sans-serif;font-size: 12px;}

.IconoPequenio{width: 24px;height: 24px; background-size: 24px; background-repeat: no-repeat;}

The javascript file ratethis.js come with this source code:

$.fn.extend({ratethis: function(options) {

var ratethis=this;
var varSelect=”Selector”;
var icon_description=”–“;
defaults = { allicons:[
{“emocion”:”amo”,”TextIcon”:”I love him”},
{“emocion”:”molesto”,”TextIcon”:”It bothers me”},
{“emocion”:”asusta”,”TextIcon”:”It scares me”},
{“emocion”:”divierte”,”TextIcon”:”I enjoy”},
{“emocion”:”gusta”,”TextIcon”:”I like it”},
{“emocion”:”triste”,”TextIcon”:”It saddens me”},
{“emocion”:”asombro”,”TextIcon”:”It amazes me”},
{“emocion”:”alegre”,”TextIcon”:”I am glad”}
var options = $.extend({}, defaults, options);

$(ratethis).each(function( index ) {
var UnicoID =;
$(this).attr(“class”,$(ratethis).attr(“class”)+” “+UnicoID);
var FirstSelect=”alegre”;
FirstElement=FirstElement+'<div data_info=”‘+icon_description+'” ‘;
FirstElement=FirstElement+'”  class=”‘+varSelect;
FirstElement=FirstElement+’ selectorFace ‘+FirstSelect+'”></div>’;

$(document).ready(function() {
All_Icons='<div class=”ratethis”>’;
$.each(options.allicons, function(index,emo ){
All_Icons=All_Icons+'<div data_info=”‘+emo.TextIcon;
All_Icons=All_Icons+'” class=”‘+emo.emocion+'”></div>’;
$(‘.ratethis div’).hover(function(){
var title = $(this).attr(‘data_info’);
$(this).data(‘tipText’, title).removeAttr(‘data_info’);
$(‘<p class=”MessageText”></p>’).text(title).appendTo(‘body’).fadeIn(‘slow’);
},function() {
$(this).attr(‘data_info’, $(this).data(‘tipText’));
}).mousemove(function(e) {
var RatonX = e.pageX – 20;var RatonY = e.pageY – 60;
$(‘.MessageText’).css({ top: RatonY, left: RatonX })
$( ‘.’+varSelect ).hover(function(e) {
SelectEmoticon= $(this);
var RatonX = e.pageX – 20;var RatonY = e.pageY – 60;
$( “.ratethis” ).css({ top: RatonY, left: RatonX });
$( “.ratethis” ).show();
$( “.ratethis div” ).click(function() {

SelectEmoticon.attr(“class”,varSelect+” selectorFace  “+$(this).attr(‘class’));


$(document).mouseup(function (e){  $( “.ratethis” ).hide();});


You will need also one test.png image width / height = 48 x 384 with 8 emoticons.

All of this file and jquery-2.2.0.js will be into your folder project.

About how is made is one selection over icons with one id.

You will see also text for each emoticon and the result will be show on your project webpage.

NOTE: This example is a fork for code by oscaruhp.
I make some changes to see how you can used.
You can see all project on this:

# FaceMocion

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

Simple shadow text with CSS with webkit-filter.

This simple example will put one shadow to the text.

The source code is simple and the goal come with filter and webkit-filter: drop-shadow.

<!DOCTYPE html>
<title>Exemple text shadow.</title>
width: 300px;
height: 300px;
float: left;

-webkit-filter: drop-shadow(5px 5px 5px black);
filter: drop-shadow(5px 5px 5px black);

<div class=”element”>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer feugiat lectus placerat sem tincidunt consequat. Nullam euismod enim vel ante cursus accumsan. Fusce pulvinar rhoncus luctus.</div>

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