我的博客左边有一个”钓鱼式”广告,相信有不少朋友已经上了钩。
俗话说,愿者上钩。再说了,既然已经点开了,你好意思不点一下广告吗?
其他都是外话,下面说一下这个小广告的实现方法。
首先,这是通过jQuery实现的。
jQuery 代码:
jQuery(document).ready(function($) {
//上下跟随滑动效果
var s= $('#adbg').offset().top; //取得id="adbg"元素相对当前窗口的高度,并赋值给 s
$(window).scroll(function (){ //浏览器滚动条触发事件
$("#adbg").animate({top : $(window).scrollTop() + 200 + "px" },{queue:false,duration:500},"easeInOutCubic");
//添加id="adbg"元素自定义动画,使其滑动"滚动条距顶部高度+ s "距离,动画过程为500毫秒;
});
$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');// 这行是 Opera 的补丁, 少了它 Opera 是直接用跳的而且画面闪烁 by willin
$('#comments #top').click(function(){
$body.animate({scrollTop: $('#header').offset().top}, 1800,"easeInOutCubic");
return false;// 返回false可以避免在原链接后加上 /*ijomyo*/ #
});
//广告
$("#adbg").hover(
function() {
// 鼠标悬停时候被触发的函数
$(this).stop().animate({'left':'+=202px'},250,"easeInOutCubic");
},
function() {
// 鼠标移出时候被触发的函数 /*ijomyo*/
$(this).stop().animate({'left':'-202px'},250,"easeInOutCubic");
});
});
在主题文件的适当部位(比如我的主题是在footer.php文件中)写入:
另外,还可以在style.css中对样式进行自定义。
#adbg{ position: absolute;left:-203px; top:150px; background:url(images/ad.png) no-repeat; width:235px; height:231px;}
#ad{ width:180px; height:150px; margin:63px 0 0 10px}

呵呵。还真没留意到。
不错的想法。。