我正在尝试在我的网站上实现这个简单的jQuery Exit LightBox ... (http://www.tonylea.com/2011/creating-a-jquery-exit-popup/)
弹出窗口非常巧妙和简单,但只有当访问者位于页面顶部时才会起作用。如果访问者向下滚动,它将无法工作。有人向PHP提出以下修复以解决此问题,但是当我在Dreamweaver中编辑它时,它会不断抛出语法错误。
有人注意到错误或可能修复的地方吗?谢谢你们!
var oldPosition = -1;
$(document).ready(function() {
$(document).mousemove(function(e) {
$('#exitpopup').css('left', (window.innerWidth / 2 – $('#exitpopup').width() / 2));
$('#exitpopup').css('top', (window.innerHeight / 2 – $('#exitpopup').height() / 2));
var position = e.pageY – $(window).scrollTop();
if(position < 10) {
if(oldPosition != -1) {
if(position < oldPosition) {
// Show the exit popup
$('#exitpopup_bg').fadeIn();
$('#exitpopup').fadeIn();
}
oldPosition = position;
} else {
oldPosition = position;
}
}
$('#divData').html(oldPosition + " : " + position);
});
$('#exitpopup_bg').click(function() {
$('#exitpopup_bg').fadeOut();
$('#exitpopup').slideUp();
});
});
答案 0 :(得分:3)
问题在于以下几行:
$('#exitpopup').css('left', (window.innerWidth / 2 – $('#exitpopup').width() / 2));
$('#exitpopup').css('top', (window.innerHeight / 2 – $('#exitpopup').height() / 2));
var position = e.pageY – $(window).scrollTop();
将–
替换为减号-
。
$('#exitpopup').css('left', (window.innerWidth / 2 - $('#exitpopup').width() / 2));
$('#exitpopup').css('top', (window.innerHeight / 2 - $('#exitpopup').height() / 2));
var position = e.pageY - $(window).scrollTop();