Skip to content

Instantly share code, notes, and snippets.

@zhuzhuaicoding
Created October 27, 2012 06:19
Show Gist options
  • Select an option

  • Save zhuzhuaicoding/3963182 to your computer and use it in GitHub Desktop.

Select an option

Save zhuzhuaicoding/3963182 to your computer and use it in GitHub Desktop.
fixed style use javascirpt
/* It is not possible to get certain styles set in css such as display using
the normal javascript. So we have to use this function taken from:
http://www.quirksmode.org/dom/getstyles.html */
function getStyle(el,styleProp)
{
var x = document.getElementById(el);
if (x.currentStyle) // IE
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle) // FF
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;
}
function your_popup_function()
{
div_id = 'helpwindow';
if (getStyle(div_id, 'left') == '1px') // only scroll if mobile. This is set in mobile.css
{
move_alert(div_id);
window.onscroll = function()
{
move_alert(div_id);
}
}
}
function move_alert(div_id)
{
// get current top
if (document.documentElement.scrollTop) // Needed if you use doctype loose.htm
current_top = document.documentElement.scrollTop;
else
current_top = document.body.scrollTop;
// get current bottom
if (document.documentElement.clientHeight) // Needed if you use doctype loose.htm
current_bottom = current_top + document.documentElement.clientHeight;
else
current_bottom = current_top + document.body.clientHeight;
alert_div = document.getElementById(div_id);
alert_div.style.position = 'absolute';
// alert_div.style.top = current_bottom - alert_div.offsetHeight; // Not working on iphone
alert_div.style.top = current_top;
} // end function move_alert(div_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment