I was trying for it and came out with an idea so that we can show the text and messages as someone is typing it (of course that's an illusion like much of other things).
So here it goes. You have a text message and you want to show it with the effect, first of all we need to break the sentence for each single letter or alphabet and then would need to put it one after another with certain time-difference. the logic seems simple.
So here is the primary function for it :-
function demoTypeWriting(){
var text = "Our whole theory of education is based on the absurd notion that we must learn to swim on land before tackling the water."
var textArray = text.split("");
$('div#resultDiv').append('<div id="typeText"></div>');
timer = setInterval( function(){writeText(textArray)}, 500 );
}
Once it's done, I would provide for the function which will actually execute the task of typing the text :-
So as you can see I am doing nothing great I am putting first element into the designated div and since it's already has been put, I am removing it from the array, So that next element can be put. Finally when array is empty I am stopping the timer.
For showing, choosing date jQuery UI datepicker is a great plugin, it provides a lot of functionality. However I feel it's little short on events, yet enough to fulfill almost all need of a basic application.
I was using that however I found an issue......with a few logic I was updating a date field which have a date picker when another field with datepicker was updated.
Problem : the primary datepicker was is visible and secondary is well say gets visible only when user wants. Since I was updating the secondary even when it was hidden.....it popped a calendar at the bottom of the page which of course was an annoying issue since it didn't use to disappear until and unless user clicks on some other datepicker enabled field.
I figured it out that the problem was with datepicker setDate function...I was using
$('.date-pick').datepicker('setDate', newDate) //where date is a js date object.
I found that there is a hide function in datepicker, I tried that but it couldn't solve the problem
Hence I started to google it out......but didn't really got a satisfactory solution, but found out that few other people were facing the same problem. I got a hint from some site then I started looking into the datepicker js (I certainly am not a js expert).
there in the _setDateDatepicker function after setting the date value in the target it was calling _updateDatepicker which I assumed was popping the datepicker calendar but since the target was hidden it couldn't get the exact position hence it showed the calendar on the bottom left of the page.
So I commented that _updateDatepicker function out and it stopped popping the calendar while setting the date.
Many times you have seen that the columns or headers freezes when you scroll horizontally or vertically respectively in a table. It looks rather cool but more than that its very useful hence nowhere you loses the track on any cell as which column and which header it belongs to irrespective of where the cell is in large table.
Let's see what can be done
let me describe it a bit in condDiv div I have two input elements where a person can provide the number of rows and columns for creating a dynamic table by clicking on the create Table button
the resultTable div is the div which will hold the dynamic table created and on scrolling of the div the function movestickyColumn(this) is called with passing the div object to it.
also note that it holds two empty and hidden div sticky-column and sticky-row (idea is to hold the frozen part of table in these divs).
Now the script part one by one, first for creating dynamic table we will have functions as follow
validations -
function val_table(){
var row= $('#condDiv #inputRow').val();
var column = $('#condDiv #inputColumn').val();
if(typeof row == "undefined" || row == null || row == "" || row <= 0 || isNaN(row) || typeof column == "undefined" || column == null || column == "" || column <= 0 || isNaN(column)){
alert("Please provide valid positive value for rows and columns");
return false;
}
else if(row>500 || column>500){
alert("The column or row can not be more than 500");
return false;
}
else{
if($("#resultTable #myTable").length > 0){
$("#resultTable #myTable").remove();
}
$("#resultTable").append(create_table(column,row));
stickyColumnNew(2);
stickyRow();
}
}
first of all I am validating the number of row and columns provided in the input field, if it is I am calling three functions
then for getting the frozen columns to be formed in the sticky-column div, function stickyColumnNew(2) is called. note that I am passing 2 as an argument to freeze first 2 columns, you can pass more or less.
function stickyColumnNew(col) {
$("#sticky-column").html('');
// var trlength = $('table.table_sorter tbody tr').length;
var documentFragment =[];
documentFragment.push('<table class="sticky-col-table scrollTable">');
var docHead = [];
docHead.push("<thead><tr>");
var docBody = [];
docBody.push("<tbody>")
var count = 0;
$("#myTable thead tr th").each(function(){
if(count < col){
docHead.push("<th style='height:"+$(this).outerHeight()+";'>"+$(this).html()+"</th>"); //use outerHeight() to get the height with padding, border and margin
}
count++;
});
docHead.push("</tr></thead>");
$("#myTable tbody tr").each(function(){
docBody.push("<tr>")
if(col >= 1){
docBody.push("<td style='height:"+$(this).find('td:first').outerHeight()+";'>"+$(this).find('td:first').html()+"</td>");
}
if(col >= 2){
for(val=2; val<=col; val++){
docBody.push("<td>"+$(this).find('td:nth-child('+val+')').html()+"</td>");
}
}
docBody.push("</tr>")
});
docBody.push("</tbody>");
documentFragment.push(docHead.join("")+docBody.join("")+'</table>');
$("#sticky-column").append(documentFragment.join(''));
}
Basically I am creating a dummy table with only the 2 columns I have to freeze, It's cell should have the same height and content as the original table and I am simply putting that table in sticky-column div
In the same fashion I will create the table with dummy header with function stickyRow
function stickyRow() {
$("#sticky-row").html('');
// var trlength = $('table.table_sorter tbody tr').length;
var documentFragment =[];
documentFragment.push('<table class="sticky-row-table scrollTable">');
var docHead = [];
docHead.push("<thead><tr>");
$("#myTable thead tr th").each(function(){
docHead.push("<th style='height:"+$(this).outerHeight()+";'><div style='width:"+$(this).width()+";'>"+$(this).html()+"</div></th>"); //use outerHeight() to get the height with padding, border and margin
});
docHead.push("</tr></thead>");
documentFragment.push(docHead.join("")+'</table>');
$("#sticky-row").append(documentFragment.join(''));
}
Now the only part left is the movestickyColumn on the div
So actually I am checking that as soon as the vertical or horizontal scroll crosses the 50px margin I am displaying the sticky-row and sticky-column divs respectively and accordingly.
feel free to play, customize or enhance upon it
hope it helps.
Try it here : -
[As far as I have checked there is some problem as in firefox header row width is not aligned and in chrome the columns height are not aligned. I guess some conflict with blogger css and css I am using. Trying to find the solution. However independently I have checked in both browser as working fine.]
First of all we need to have a HTML container where we can define hour, minute and seconds.
the different counter i.e. the values of hour, minute or second are put in div with id
counterHour, counterMin and counterSec as can be seen below.
As we can see there is an onclick attribute and check_timer() function is attached to it.
Hence in script (<script></script>) tag we will define below functions.
in check_timer function I am checking if it's start timer or stop timer with the help of class 'start'.
and I am alternately starting the set interval and stopping the set interval respectively with changing the value of button.
the logic is pretty simple...set an interval of one second to increase the value of counterSec div.
Simultaneously I am checking if it is 60th second to increase the minute counter also if it is 60th minute to increase the hour counter.