2

First apologize for my English. I have a popup when I do click in triggerPop this one it appears, I'm trying to show this one to the right but the css doesn't work. What am I doing wrong? Thank you in advance.

var monscreen = $(window).width();
var mondoc = $(document).width();

if (mondoc > monscreen) {
    var dif = mondoc - monscreen;
    $("div#Navigation_Popup").css({
        'right': dif + 'px'
    });
}

$(function() {
    $('#triggerPop').bind('click', function(e) {
        $("#Navigation_Popup").slideFadeToggle(function() {});
        return false;
    });

    $.fn.slideFadeToggle = function(easing, callback) {
        return this.animate({
            opacity: 'toggle',
            height: 'toggle'
        }, "fast", easing, callback);
    }
});​
4

3 回答 3

1

我要离开有限的信息。你提到css...

我会移动所有这些代码:

var monscreen = $(window).width();
var mondoc = $(document).width();

if (mondoc > monscreen) {
  var dif = mondoc - monscreen;
  $("div#Navigation_Popup").css({
    'right': dif + 'px'
  });
}

代替

$(function(){
  .
  .
  .
});

就像现在一样,if (mondoc > monscreen)代码块在文档准备好之前就被执行了。

于 2012-10-11T13:35:32.640 回答
0

不确定 jquery 如何处理这些值,但不是 var monscreen = $(window).width(); var mondoc = $(document).width(); 返回字符串?提醒检查这个怎么样?

于 2012-10-11T13:36:12.397 回答
0

绑定已弃用,请尝试使用。我也认为一切都应该在 $(function()) 处理程序中,所以,试试这个:

$(function() {
    var monscreen = $(window).width();
     var mondoc = $(document).width();

    if (mondoc > monscreen) {
        var dif = mondoc - monscreen;
        $("div#Navigation_Popup").css({
           'right': dif + 'px'
        });
    }
    $('#triggerPop').on('click', function(e) {
        $("#Navigation_Popup").slideFadeToggle(function() {});
        return false;
    });

    $.fn.slideFadeToggle = function(easing, callback) {
        return this.animate({
            opacity: 'toggle',
            height: 'toggle'
        }, "fast", easing, callback);
    }
});
于 2012-10-11T13:40:22.740 回答