【问题标题】:DIV Not Being Generated in IE7 with jQuery使用 jQuery 在 IE7 中未生成 DIV
【发布时间】:2012-02-11 02:52:21
【问题描述】:

我不明白为什么这个脚本在 IE7 和 8 中不起作用。它在所有其他浏览器中都可以正常工作,但由于某种原因,在 IE7 和 8 中,这个脚本只触发了// thumbs hover 位,并且不是// loading images 位(实际上更重要)。一切似乎都很好,有人有什么想法吗?

     function featuredJS() {

        $("[title]").attr("title", function(i, title) {
            $(this).data("title", title).removeAttr("title");
        });

        // loading images

        var last = "featured/01.jpg";

        $("#thumbs a").click(function(event) {
            event.preventDefault();
            var position = $(this).attr("class");
            var graphic = $(this).attr("href");
            var title = $(this).attr("alt");
            var description = $(this).data("title");
            var currentMargin = $("#full-wrapper #full").css("marginLeft");
            var currentWidth = $("#full-wrapper #full").css("width");
            var transitionTest = currentMargin.replace("px", "") * 1;
            if(last != graphic && ((transitionTest % 938) == 0 || transitionTest == 0)) {
                $("#placeholder").before( "<div class='featured'><div class='description " + position + "'>" + "<h3>" + title + "</h3>" + "<p>" + description + "</p>" + "</div><img src=\"" + graphic + "\" /><div style='clear:both;'></div></div>" );

                $("#full-wrapper #full").animate({
                    marginLeft: "-=938px"
                }, 500);

                $("#full-wrapper #full").css("width","+=938px");
                last = graphic;
            };
        });

        // thumbs hover

        $("#thumbs .thumb").hover(
            function () {
                $(this).find(".red-bar").animate({height:"72px"},{queue:false,duration:500});
            },
            function () {
                $(this).find(".red-bar").animate({height:"3px"},{queue:false,duration:500});
            }
        );

    };

演示页面http://www.weblinxinc.com/beta/welex/demo/

【问题讨论】:

    标签: javascript jquery html css internet-explorer


    【解决方案1】:

    您的问题是由于没有设置margin 开始的。 transitionTest 然后变成NaN,因为样式是auto,而不是0px,就像您期望的那样。考虑改用这个:

    var transitionTest = parseInt("0"+currentMargin,10);
    

    这将为您修剪“px”,并处理边距是关键字的情况。

    【讨论】:

      猜你喜欢
      • 2010-12-07
      • 2012-01-11
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      • 2012-01-23
      相关资源
      最近更新 更多