php底部悬浮广告,左右飘浮广告(jq方法实现)

思路:

在头部添加-宽度1000px的层作为左右漂浮层的参考层(position:relative),左右漂浮层(position:absolute)。

其中,左边漂浮层 left=- 自身的宽度 ,右边漂浮层right=- 自身的宽;

左右漂浮层top= 窗口高度- 漂浮层的高度 +滚动条距页面顶部的高度(漂浮层贴浏览器底部浮动)

或 (窗口高度- 漂浮层的高度)/2 +滚动条距页面顶部的高度 (漂浮层贴浏览器中部浮动)

实例代码:

无标题文档

html,body{overflow-x:hidden; overflow-y:auto;}/* 去除因左右浮动产生的横向滚动条的 关键 */

*{margin:0;padding:0;}

ul li{ list-style:none;}

img {border:0 none;}

input[type='button']{width:100px; height:38px;display:block;position:fixed;right:20%; top:50px;}

.w1{ background:#CCC;}

.header{background: #CCC; position:relative;}

.header .w98{height:104px;margin:0 auto;position:relative;width:1000px; border:1px #f00 solid;z-index:10;}

.main{clear:both;height:auto !important;margin-top:-3px;padding-top:30px; background:#c1ccdc;}

.main .w1{clear:both;margin:0 auto;width:1000px;border:1px #f00 solid;}

.footer{clear:both;padding:80px 0 0;}

.footer .w1{margin:0 auto;width:1000px; border:0 none;}

/* christmas */

.cs{width:1000px; height:100px; border:1px blue solid; position:absolute;left:50%; top:0;margin-left:-500px;z-index:5;}/* 漂浮参考层用绝对定位不占页面位置*/

.csleft,.csright{width:366px;height:438px; border:1px #00CC33 solid; position:absolute; top:150px;}

.csleft{ left:-369px; background: url(https://phpvar.com/wp-content/uploads/fleft2.png) no-repeat;}

.csright{right:-368px; background: url(https://phpvar.com/wp-content/uploads/fright2.png) no-repeat;}

$(document).ready(function(e) {

//var wheight=($(window).height()-$(".csleft").height())/2; //默认中间浮动: (窗口高度- 漂浮元素本身高度)/2

var ptop=($(window).height()-$(".csleft").height())-10; //打开页面默认漂浮位置-> 底部浮动:(窗口高度- 漂浮元素本身高度),减10px 避免拉动滚动条时页面出现第2条纵向滚动条

$(".csleft,.csright").css({

top:ptop

})

//alert(ptop);

$(window).scroll(

function(){

var ftop=$(window).scrollTop();

var wheight=($(window).height()-$(".csleft").height())-6;

$(".csleft,.csright").animate({

top: wheight+ftop },150); //拉动滚动条时,top值=打开页面默认top值+滚动条距页面顶部位置的值

}

)

function winsize(){

//alert($(window).width());

if($(window).width()<1400 || window.screen.width<1440){ //当浏览器窗口小于1400px 或 分辨率小于1440(19.1寸显示屏)时,不显示浮动层

$(".csleft,.csright").hide();

}else{

$(".csleft,.csright").show();

}

}

winsize();

$(window).resize(winsize) // 窗口大小改变时调用winsize()函数

});

main

提示:你可以先修改部分代码再运行。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值