Javascript代码修改...简单错误?

时间:2013-12-11 06:04:39

标签: javascript jquery

我正在尝试在我的网站上实现这个简单的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();
    });
});

1 个答案:

答案 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();