/**
* Move element to vertical point.
*
* @param object element
* @param int yPoint
*/
function js_move_elementToYPos(element, yPoint){
element.style.position = 'absolute';
element.style.top = yPoint;
}
PHP and javascript snippets you can copy and paste.
Friday, June 8, 2007
js_move_elementToXPos(element, xPoint)
/**
* Move element to horizontal point.
*
* @param object element
* @param int xPoint
*/
function js_move_elementToXPos(element, xPoint){
element.style.position = 'absolute';
element.style.left = xPoint;
}
* Move element to horizontal point.
*
* @param object element
* @param int xPoint
*/
function js_move_elementToXPos(element, xPoint){
element.style.position = 'absolute';
element.style.left = xPoint;
}
Thursday, June 7, 2007
js_move_elementHorizontal(element, shiftHoriz)
/**
* Move element horizontally.
*
* @param object element
* @param int shiftHorizontal
*/
function js_move_elementHorizontal(element, shiftHoriz){
element.style.position = 'relative';
element.style.left = shiftHoriz;
}
* Move element horizontally.
*
* @param object element
* @param int shiftHorizontal
*/
function js_move_elementHorizontal(element, shiftHoriz){
element.style.position = 'relative';
element.style.left = shiftHoriz;
}
js_move_elementVertical(element, shiftVertical)
/**
* Move element vertically.
*
* @param object element
* @param int shiftVertical
*/
function js_move_elementVertical(element, shiftVertical){
element.style.position = 'relative';
element.style.top = shiftVertical;
}
* Move element vertically.
*
* @param object element
* @param int shiftVertical
*/
function js_move_elementVertical(element, shiftVertical){
element.style.position = 'relative';
element.style.top = shiftVertical;
}
js_get_rand(max)
/**
* Gets a random number
*
* @param int max
* @return int
*/
function js_get_rand(max){
return Math.random()*max;
}
* Gets a random number
*
* @param int max
* @return int
*/
function js_get_rand(max){
return Math.random()*max;
}
js_get_isEven(n)
/**
* Gets whether a number is even
*
* @param int n
* @return int
*/
function js_get_is_even(n){
return n % 2 == 0?true:false;
}
* Gets whether a number is even
*
* @param int n
* @return int
*/
function js_get_is_even(n){
return n % 2 == 0?true:false;
}
js_is_odd(n)
/**
* Gets whether a number is odd.
*
* @param int n
* @return int
*/
function is_odd(n){
return n % 2 == 0?false:true;
}
* Gets whether a number is odd.
*
* @param int n
* @return int
*/
function is_odd(n){
return n % 2 == 0?false:true;
}
js_get_screenCenterY()
/**
* Gets the middle vertical point of the page
*/
function js_get_screenCenterY(){
return ( window.outerHeight - getScrollTop())/2;
}
* Gets the middle vertical point of the page
*/
function js_get_screenCenterY(){
return ( window.outerHeight - getScrollTop())/2;
}
js_get_screenCenterX()
/**
* Gets the middle horizontal point of the page.
*/
function js_get_screenCenterX(){
return (window.outerWidth - js_get_scrollLeft())/2;
}
* Gets the middle horizontal point of the page.
*/
function js_get_screenCenterX(){
return (window.outerWidth - js_get_scrollLeft())/2;
}
js_get_elementTop()
/**
* Gets the vertical position of an element.
*
* Credit: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_top_left.asp
*/
function js_get_elementTop(elem) {
yPos = elem.offsetTop;
tempEl = elem.offsetParent;
while (tempEl != null) {
yPos += tempEl.offsetTop;
tempEl = tempEl.offsetParent;
}
return yPos;
}
* Gets the vertical position of an element.
*
* Credit: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_top_left.asp
*/
function js_get_elementTop(elem) {
yPos = elem.offsetTop;
tempEl = elem.offsetParent;
while (tempEl != null) {
yPos += tempEl.offsetTop;
tempEl = tempEl.offsetParent;
}
return yPos;
}
js_get_elementLeft()
/**
* Gets the horizontal position of an element.
*
* Credit: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_top_left.asp
*/
function js_get_elementLeft(elem) {
xPos = elem.offsetLeft;
tempEl = elem.offsetParent;
while (tempEl != null) {
xPos += tempEl.offsetLeft;
tempEl = tempEl.offsetParent;
}
return xPos;
}
* Gets the horizontal position of an element.
*
* Credit: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_top_left.asp
*/
function js_get_elementLeft(elem) {
xPos = elem.offsetLeft;
tempEl = elem.offsetParent;
while (tempEl != null) {
xPos += tempEl.offsetLeft;
tempEl = tempEl.offsetParent;
}
return xPos;
}
js_get_elementHeight()
/**
* Gets the height of an element.
*
* Credit: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_width_height.asp
*/
function js_get_elementHeight(elem) {
if (elem.style.pixelHeight) {
xPos = elem.style.pixelHeight;
}
else {
xPos = elem.offsetHeight;
}
return xPos;
}
* Gets the height of an element.
*
* Credit: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_width_height.asp
*/
function js_get_elementHeight(elem) {
if (elem.style.pixelHeight) {
xPos = elem.style.pixelHeight;
}
else {
xPos = elem.offsetHeight;
}
return xPos;
}
js_get_elementWidth
/**
* Get the width of an element
*
* Credit: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_width_height.asp
*/
function js_get_elementWidth(elem) {
if (elem.style.pixelWidth) {
xPos = elem.style.pixelWidth;
}
else {
xPos = elem.offsetWidth;
}
return xPos;
}
* Get the width of an element
*
* Credit: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_width_height.asp
*/
function js_get_elementWidth(elem) {
if (elem.style.pixelWidth) {
xPos = elem.style.pixelWidth;
}
else {
xPos = elem.offsetWidth;
}
return xPos;
}
js_get_pageWidth()
/**
* Gets the width of a page
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*/
function js_get_pageWidth(){
var x;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{
x = document.body.scrollWidth;
}
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
{
x = document.body.offsetWidth;
}
return x;
}
* Gets the width of a page
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*/
function js_get_pageWidth(){
var x;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{
x = document.body.scrollWidth;
}
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
{
x = document.body.offsetWidth;
}
return x;
}
js_get_pageHeight()
/**
* Gets the page height.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*/
function js_get_pageHeight(){
var y;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{
y = document.body.scrollHeight;
}
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
{
y = document.body.offsetHeight;
}
return y;
}
* Gets the page height.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*/
function js_get_pageHeight(){
var y;
var test1 = document.body.scrollHeight;
var test2 = document.body.offsetHeight
if (test1 > test2) // all but Explorer Mac
{
y = document.body.scrollHeight;
}
else // Explorer Mac;
//would also work in Explorer 6 Strict, Mozilla and Safari
{
y = document.body.offsetHeight;
}
return y;
}
js_get_scrollTop()
/**
* Gets the amount the page has been scrolled down.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*/
function js_get_scrollTop(){
if (self.pageYOffset) // all except Explorer
{
y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
y = document.body.scrollTop;
}
return y;
}
* Gets the amount the page has been scrolled down.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*/
function js_get_scrollTop(){
if (self.pageYOffset) // all except Explorer
{
y = self.pageYOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
y = document.body.scrollTop;
}
return y;
}
js_get_scrollLeft()
/**
* Gets how much the page has been scrolled left.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*
*/
function js_get_scrollLeft(){
if (self.pageYOffset) // all except Explorer
{
x = self.pageXOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
x = document.documentElement.scrollLeft;
}
else if (document.body) // all other Explorers
{
x = document.body.scrollLeft;
}
return x;
}
* Gets how much the page has been scrolled left.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*
*/
function js_get_scrollLeft(){
if (self.pageYOffset) // all except Explorer
{
x = self.pageXOffset;
}
else if (document.documentElement && document.documentElement.scrollTop)
// Explorer 6 Strict
{
x = document.documentElement.scrollLeft;
}
else if (document.body) // all other Explorers
{
x = document.body.scrollLeft;
}
return x;
}
js_get_browserInnerHeight
/**
* Gets the inner height of the browser page.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*/
function js_get_browserInnerHeight(){
if (self.innerHeight) // all except Explorer
{
x = self.innerWidth;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
x = document.documentElement.clientWidth;
}
else if (document.body) // other Explorers
{
x = document.body.clientWidth;
}
return x;
}
* Gets the inner height of the browser page.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*/
function js_get_browserInnerHeight(){
if (self.innerHeight) // all except Explorer
{
x = self.innerWidth;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
x = document.documentElement.clientWidth;
}
else if (document.body) // other Explorers
{
x = document.body.clientWidth;
}
return x;
}
js_get_browserInnerWidth
/**
* Gets the inner width of the browser page.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*
function js_get_browserInnerWidth(){
if (self.innerHeight) // all except Explorer
{
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
y = document.body.clientHeight;
}
return y;
}
* Gets the inner width of the browser page.
*
* Credit: http://www.quirksmode.org/viewport/compatibility.html
*
function js_get_browserInnerWidth(){
if (self.innerHeight) // all except Explorer
{
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
y = document.body.clientHeight;
}
return y;
}
js_get_pageInnerWidth
function js_get_pageInnerWidth(){
// http://www.quirksmode.org/viewport/compatibility.html
if (self.innerHeight) // all except Explorer
{
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
y = document.body.clientHeight;
}
return y;
}
// http://www.quirksmode.org/viewport/compatibility.html
if (self.innerHeight) // all except Explorer
{
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
y = document.body.clientHeight;
}
return y;
}
Subscribe to:
Posts (Atom)
Blog Archive
-
▼
2007
(71)
-
▼
June
(20)
- js_move_elementToYPos(element, yPoint)
- js_move_elementToXPos(element, xPoint)
- js_move_elementHorizontal(element, shiftHoriz)
- js_move_elementVertical(element, shiftVertical)
- js_get_rand(max)
- js_get_isEven(n)
- js_is_odd(n)
- js_get_screenCenterY()
- js_get_screenCenterX()
- js_get_elementTop()
- js_get_elementLeft()
- js_get_elementHeight()
- js_get_elementWidth
- js_get_pageWidth()
- js_get_pageHeight()
- js_get_scrollTop()
- js_get_scrollLeft()
- js_get_browserInnerHeight
- js_get_browserInnerWidth
- js_get_pageInnerWidth
-
▼
June
(20)