简体   繁体   English

CSS jQuery不起作用

[英]css jquery doesn't work

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. 当我确实点击triggerPop时,我有一个弹出窗口,它出现了,我试图向右显示此窗口,但css无法正常工作。 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);
    }
});​

I'm going off of the limited information. 我要讲的是有限的信息。 You mentioned css ... 你提到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. 到目前为止,在准备好文档之前, if (mondoc > monscreen)代码块正在执行。

Not sure how jquery treat these values but, isnt var monscreen = $(window).width(); 不确定jquery如何处理这些值,但是isnt var monscreen = $(window).width(); var mondoc = $(document).width(); var mondoc = $(document).width(); returning strings? 返回字符串? How about an alert to check this? 警报检查一下如何?

Bind is deprecated, try on instead. 绑定已弃用,请尝试。 I also think everything should be inside $(function()) handler, so, try this: 我还认为所有内容都应在$(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);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM