国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > CSS > 正文

IE6下position fixed失效的解決方法(親測有效)

2024-07-11 08:36:58
字體:
供稿:網(wǎng)友

在網(wǎng)上找了好久,終于找到一種親測有效的解決方法。


<!–[if IE 6]>
<script type=”text/javascript”>
(function($) {
jQuery.fn.Fixed = function(options) {
var defaults = {
x:0,
y:0
};
var o = jQuery.extend(defaults, options);
var isIe6 = !window.XMLHttpRequest;
var html= $(‘html’);
if (isIe6 && html.css(‘backgroundAttachment’) !== ‘fixed’) { //防止抖動
html.css(‘backgroundAttachment’,’fixed’)
.css(‘backgroundImage’,’url(about:blank)’);
};
return this.each(function() {
var domThis=$(this)[0];
var objThis=$(this);
if(isIe6){
objThis.css(‘position’ , ‘absolute’);
domThis.style.setExpression(‘left’, ‘eval((document.documentElement).scrollLeft + ‘ + o.x + ‘) + “px”‘);
domThis.style.setExpression(‘top’, ‘eval((document.documentElement).scrollTop + ‘ + o.y + ‘) + “px”‘);
} else {
objThis.css(‘position’ , ‘fixed’).css(‘top’,o.y).css(‘left’,o.x);
}
});
};
})(jQuery)
</script>
<![endif]–>

調(diào)用方法如下:


<!–[if IE 6]>
<script type=”text/javascript”>
$(function(){
$(‘.float’).Fixed({x:800,y:200});
});
</script>
<![endif]–>

fixed一般應(yīng)用有兩種情況。

一,居中的彈層:


<!–[if IE 6]>
<script type=”text/javascript”>
$(function(){
//centerX和centerY是可視窗口的高和寬,需要減去自身的的寬度或高度的一半才能居中
var screenHeight=document.documentElement.clientHeight,
  screenWidth=document.documentElement.clientWidth,
floatHeight=$(‘.float’).height(),
floatWidth=$(‘.float’).width();
$(‘.float’).Fixed({
x:(screenWidth-floatWidth)/2,
y:(screenHeight-floatHeight)/2
});
});
</script>
<![endif]–>

二,靠右的彈層,類似于回到頂部等:


<!–[if IE 6]>
<script type=”text/javascript”>
$(function(){
//centerX和centerY是可視窗口的高和寬,高度自定義,寬度為屏幕寬度-浮層寬度
var screenHeight=document.documentElement.clientHeight,
  screenWidth=document.documentElement.clientWidth,
floatHeight=$(‘.float’).height(),
floatWidth=$(‘.float’).width();
$(‘.float’).Fixed({
x:screenWidth-floatWidth,
y:300
});
});
</script>
<![endif]–>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 万源市| 荣昌县| 堆龙德庆县| 嫩江县| 吉木萨尔县| 库车县| 新泰市| 大英县| 米泉市| 尤溪县| 屯昌县| 台南县| 建宁县| 色达县| 交城县| 洞头县| 凌海市| 扶余县| 城固县| 乐东| 绥阳县| 星子县| 油尖旺区| 青海省| 宁安市| 本溪| 丰城市| 临城县| 万宁市| 正宁县| 筠连县| 余江县| 永修县| 靖宇县| 瓮安县| 杂多县| 阿鲁科尔沁旗| 蓬溪县| 高尔夫| 平和县| 新龙县|