jquery图片对联广告制作jQuery侧面浮动图片广告

2018-01-12     浏览次数:

今天在网站加了一个对联的广告,吾爱编程把代码整理了一下分享给大家,有需要的可以看下:
<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
.fixediv{position:fixed;top:140px;z-index:9999;width:90px;height:300px;background:#ddd;margin:0px 100px;}
.fixediv img{float:left;}
.fixediv a.close{display:block;height:30px;line-height:30px;background:#fff;font-size:14px;padding:0 10px;color:#5e5e5e;text-decoration:none;text-align:center;}
.leftadv{left:0px;}
.rightadv{right:0px;}
</style>

<div class="fixediv leftadv">
    <a href="www.itbiancheng.com"><img src="/static/images/lALPBbCc1U2yqMvNASxa_90_300.png" width="90" height="300" alt="极品三国" /></a>
    <a class="close" href="javascript:void(0);">关闭广告</a>
</div>
<div class="fixediv rightadv">
    <a href="www.itbiancheng.com"><img src="/static/images/lALPBbCc1U2zbk3NASxa_90_300.png" width="90" height="300" alt="极品三国" /></a>
    <a class="close" href="javascript:void(0);">关闭广告</a>
</div>
<script type="text/javascript">
$(document).ready(function(){
    $(".fixediv a").click(function(){
        $(".fixediv").fadeOut(400);
    });
    $(".fixediv").floatadv();
});

jQuery.fn.floatadv = function(loaded) {
    var obj = this;
    body_height = parseInt($(window).height());
    block_height = parseInt(obj.height());
    top_position = parseInt((body_height/2) - (block_height/2) + $(window).scrollTop());
    if (body_height<block_height) { top_position = 0 + $(window).scrollTop(); };
    if(!loaded) {
        obj.css({'position': 'absolute'});
        obj.css({ 'top': top_position });
        $(window).bind('resize', function() {
            obj.floatadv(!loaded);
        });
        $(window).bind('scroll', function() {
            obj.floatadv(!loaded);
        });
    } else {
        obj.stop();
        obj.css({'position': 'absolute'});
        obj.animate({ 'top': top_position }, 400, 'linear');
    }
}
</script>
效果如图所示:
*转载请注明出处,更多资料尽在 吾爱编程
返回吾爱编程首页