Jquery – Hide – Show – Fade – Slide
HIDE / SHOW
1 2 3 4 |
$(".dog").show(); $(".dog").hide(); |
FADE
1 2 3 4 5 6 |
$("#div1").fadeIn(); $("#div2").fadeIn("slow"); $("#div3").fadeIn(3000); $('#div3').fadeOut("slow"); |
1 2 3 4 5 |
$("#div1").fadeToggle(); $("#div2").fadeToggle("slow"); $("#div3").fadeToggle(3000); |
SLIDE
1 2 3 4 5 |
$("#panel").slideDown(); $("#panel").slideUp(); $("#panel").slideToggle(); |
1 2 3 |
$("#panel").toggle(); |
Slide Left/Right (You need Jquery UI)
1 2 3 4 |
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> $('#example1').hide("slide", { direction: "right" }, 1000); |
Delay
1 2 3 |
$("#step2").delay(700).show("slide", { direction: "right" }, 500); |
Easings in and out
1 2 3 4 |
$(this).animate({height: "show"}, 600, "easeOutBounce");//opens only $(this).animate({height: "hide"}, 600, "easeOutBounce");//hides only |
Can replace this boring version!
1 2 3 |
$(this).appendTo($('#ticker')).slideDown(); |
Absolute Center of screen/page
Just change the values of the margins depending on how big the item is, i.e a modal window. Then it will always stay 50% on the middle, minus your settings.
1 2 3 4 5 6 7 8 9 |
.centered { position: fixed; top: 50%; left: 50%; margin-top: -50px; margin-left: -100px; } |
Spry validation formats
First of all I don’t use, never will and also dislike Dreamweaver. It goes where the bold section is var sprytextfield1 = new Spry.Widget.ValidationTextField(“sprytextfield1”, “none”, {validateOn:[“change”]}); P.S. Don’t use speech marks if changing from “none”. var sprytextfield3 = new Spry.Widget.ValidationTextField(“sprytextfield2”, “email”, {maxChars:40}); var sprytextfield4 = new Spry.Widget.ValidationTextField(“sprytextfield3”, “none”, {minChars:6, maxChars:15}); var sprytextfield6 = new Spry.Widget.ValidationTextField(“sprytextfield5”, […]
Maximum posts change php.ini
PHP is set to only recieve 1000 fields per post!, but if you want more uncomment this in your php.ini file and set higher. php_value max_input_vars=3000 or it may be max_input_vars = 3000
Move a div across the screen .animate
1 2 3 4 5 6 7 |
$("#startAnimation").click(function(){ $(".toBeAnimated").animate({ marginLeft: "+=250px", }, 1000 ); }); |
Swatch Internet Time
Calculate Minutes of the day in Swatch Internet Time. Its now
1 2 3 |
echo $beats =date("B"); //swatch beats |
Unit Beat Conversion 1 day = 1000 .beats 1 hour = 41.6 .beats 1 min = 0.694 .beats 1 s = 0.011574 .beats
Milliseconds – Microseconds
Shows only first 13 numbers due to floating point being a problem showing decimal place.
1 2 3 |
echo substr(microtime(true) * 1000, 0, 13); |
Users online
Handy for information on session time storing also Database SQL
1 2 3 4 5 6 |
CREATE TABLE `user_online` ( `session` char(100) NOT NULL default '', `time` int(11) NOT NULL default '0' ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<?php session_start(); $session=session_id(); $time=time(); $time_check=$time-600; //SET TIME 10 Minute $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="user_online"; // Table name // Connect to server and select databse mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE session='$session'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count=="0"){ $sql1="INSERT INTO $tbl_name(session, time, name)VALUES('$session', '$time', 'mike' )"; $result1=mysql_query($sql1); } else { "$sql2=UPDATE $tbl_name SET time='$time' WHERE session = '$session'"; $result2=mysql_query($sql2); } $sql3="SELECT * FROM $tbl_name"; while($row = mysql_fetch_array($sql3)) { echo $name = $row['name']; } $result3=mysql_query($sql3); $count_user_online=mysql_num_rows($result3); echo "User online : $count_user_online "; // if over 10 minute, delete session $sql4="DELETE FROM $tbl_name WHERE time<$time_check"; $result4=mysql_query($sql4); // Open multiple browser page for result // Close connection mysql_close(); ?> |
Replacewith – Editable Textbox and Save Button
Turns a variable into an editable piece of text in a text box and a save button, when clicked displays the new amount back in a nice box without a refresh.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<div class='changeme' >1000</div> <!-- variable --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).delegate('.done', 'click', function() { $('#txtname').replaceWith(function() { $(".done").hide(); // add to api to change budget return '<div class="done">' + $(this).val() + ' - Saved...</div>'; }); }); $(".changeme").click(function() { var thevalue = $( this ).text(); $(this).replaceWith($('<form action="replacewith.php" method="get"><input id="txtname" value=' + $(this).text() + '> <input class="done" type="button" value="Save Budget"></form>')); }); </script> <style> #txtname { color: red; border: 2px solid blue; width: 110px; text-align: center; } div { color: red; border: 2px solid blue; width: 110px; margin: 3px; text-align: center; } </style> |
Select ids that increment by 1 each time
This will hide all ids that have the word ‘themessage’ in them. The normal way below is great but id you have 100 of them, this is a waste when you can explain this in a shorter way.
1 2 3 4 5 |
#themessage1, #themessage2, #themessage3 { display: none; } |
Like this…..
1 2 3 4 5 |
*[id^='themessage']{ display: none; } |
Find Percentage of a number
If I have £95,353.00 and I have spent £50,000 What is the percentage? =(£95,353.00/£50,000)*100 Gives me 52.43%
Show Array values – Jquery or Javascript
1 2 3 4 5 6 7 |
var data = ['foo', 'bar', 'foobar', 'moo', 'meow', 'xxx']; var list = $('ul'); $.each(data, function(i, value) { $('<li/>', { text: value }).hide().appendTo(list).delay(i * 1000).fadeIn(); }); |
Vertical line in css
1 2 3 4 5 6 7 |
#menu { border-left: 1px solid black; height: 100%; } |
Run tasks in parallel (using bat files)
If we want to run tasks in parallel, this can be tricky. We want 5 files to run at the same time. If each file takes 2 seconds to run, then all of them should take 2 seconds if this is true, else it will take 10 seconds. Method 1 The below example takes 10 […]
Time in milliseconds in PHP
1 2 3 |
$milliseconds = round(microtime(true) * 1000); |
Scrollable Div
1 2 3 4 5 6 7 |
table{ overflow-y:scroll; height:100px; display:block; } |
Get Percentage of a number
$total is 1232 $number is 238 The out put will show 19%
1 2 3 4 |
$percentage = round($number * 100 / $total)."%"; // Get percentage echo $percentage; |
Random number – Python
1 2 3 4 5 |
import random z = random.randint(40,100) print "first random",z |
Scroll to bottom of textarea onload – read from bottom
1 2 3 |
$("#noshchat").animate({ scrollTop:$("#noshchat")[0].scrollHeight - $("#noshchat").height()},1000); |
Delete range of data from database with limit
1 2 3 |
DELETE FROM `boxdata` WHERE `id` > 2000 LIMIT 1000 ; |
Mysqli Basic – ON DUPLICATE KEY UPDATE
The column called ‘ref’ will need to be unique. If it has a dupe, then it will complete the second part of the statement.
1 2 3 4 5 6 7 8 9 10 11 12 |
$results = $mysqli->query("INSERT INTO client_login (fname, sname, ref) VALUES ('Mike', 'Belmond','T99') ON DUPLICATE KEY UPDATE fname='Mike', sname='Belmond',ref='T100'"); if($results){ print 'Success! record updated / deleted'; }else{ print 'Error : ('. $mysqli->errno .') '. $mysqli->error; } |
What Router can I use with Onestream Broadband?
To understand this question firstly there are two types of Router available to buy if you do not have fibre fitted to your house. This would be called cable broadband. A Standard Router A router that connects devices is responsible for directing network traffic between devices within a local network (like computers, smartphones, or tablets). […]