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);
    }
});​
6
  • Can you post your HTML and a jsFiddle showing the problem? Commented Oct 11, 2012 at 13:30
  • Explain "doesn't work" (or show it). It's hard to give an answer if you don't know the exact problem. Commented Oct 11, 2012 at 13:31
  • Need html too, to solve this problem Commented Oct 11, 2012 at 13:33
  • What position is #Navigation_Popup set to? It would require absolute, relative or fixed for the right property to have any effect. Commented Oct 11, 2012 at 13:36
  • the position is absolute Commented Oct 11, 2012 at 13:53

3 Answers 3

1

I'm going off of the limited information. You mentioned css...

I would move all of this code:

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

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

Inside of

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

As it is now, the if (mondoc > monscreen) code block is getting executed before the document is ready.

Sign up to request clarification or add additional context in comments.

Comments

0

Not sure how jquery treat these values but, isnt var monscreen = $(window).width(); var mondoc = $(document).width(); returning strings? How about an alert to check this?

2 Comments

- will coerce them to numbers if necessary.
Thank you for his answers, I find my mistake :) the div, was inside an updatepanel and the ajax change the css
0

Bind is deprecated, try on instead. I also think everything should be inside $(function()) handler, so, try this:

$(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);
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.