简体   繁体   English

如何创建在IE中不会中断的选项卡式界面,让我做我想做的事情?

[英]How can I create a tabbed interface that doesn't break under IE and lets me do what I'm trying to do?

I am currently working on creating a tabbed interface that has one tab of rich flash-like content and the rest of the tabs that are full of simple text. 我目前正在创建一个选项卡式界面,其中有一个选项卡包含丰富的类似Flash的内容,其余的选项卡都包含简单的文本。 Bit of a long one here but I've pretty much exhausted my options and want to let you know what I've tried. 这里有点长,但是我几乎已经用尽了我的所有选择,并想让您知道我已经尝试了什么。 I feel like there should be a solution to my problem that doesn't feel like a terrible hack but I'm not sure what else to try. 我觉得应该有解决我的问题的方法,这听起来并不可怕,但是我不确定还有什么尝试。

The Trials 审判
To create my tabs I decided to go with jQuery for convenience sake and was happily plugging along making the usual non UI/Tools tabbed structure. 为了创建我的标签,为了方便起见,我决定使用jQuery,并且很高兴地制作了通常的非UI / Tools标签式结构。 That is to say, like this: 也就是说,像这样:

<div class="page">
    <div class="tabs">
        <ul class="nav">
            <li href="#tab_1">Tab one</li>
            <li href="#tab_1">Tab one</li>
        </ul>
    </div>
    <div class="content">
        <div id"tab_1">Stuff</div>
        <div id"tab_2">Words</div>
    </div>
</div>

From here I have all the usual CSS and jQuery business to get this going and was happy with the results. 从这里开始,我完成了所有常规的CSS和jQuery业务,并对结果感到满意。 That is, until I tried to add the rich content. 也就是说,直到我尝试添加丰富的内容。 It loads just fine and I can't really complain about that, but I was asked to make it so that the rich content does not reload upon leaving to another tab and returning. 它加载得很好,我真的不能对此抱怨,但是我被要求这样做,以使丰富的内容在离开另一个选项卡并返回时不会重新加载。

This befuddled me for some time, but after reading jQuery's documentation on the .hide() and .show() functions it became all too clear what was going on. 这使我迷惑了一段时间,但是在阅读了jQuery关于.hide()和.show()函数的文档后,一切都变得非常清楚。 hide() and show() are equivalent to display = "none" display = "block" and so every time I made these calls my content was being destroyed and needed to be reloaded. hide()和show()等效于display =“ none” display =“ block”,因此每次我进行这些调用时,我的内容都被销毁并需要重新加载。

For the sake of clarity I will show you what my jQuery looked like: 为了清楚起见,我将向您展示jQuery的外观:

$(document).ready(function() {
    var tabContainers = $('div.content > div');   
    tabContainers.hide().filter(':first').show();

    $('div.tabs ul.nav a').click(function () {

    tabContainers.hide();
    tabContainers.filter(this.hash).show();
    //selected is a CSS attribute to highlight the tabs
    $('div.tabs ul.nav a').removeClass('selected');
    $(this).addClass('selected');
    return false;
    }).filter(':first').click();
});

At this point I made some changes to the above code and instead of using show() and hide() on the rich content I began setting the visibility. 此时,我对上面的代码进行了一些更改,而不是在丰富的内容上使用show()和hide(),而是开始设置可见性。 So now my simple content was using .hide() and .show() since it didn't need to reset and my rich content was using visibility. 所以现在我的简单内容正在使用.hide()和.show(),因为它不需要重置,而我的丰富内容正在使用可见性。 Unfortunately now it was all disappearing and reappearing nicely but with a big gap from the rich content page since visibility does not physically remove the content from the page, just it's visibility. 不幸的是,现在所有内容都消失了并且很好地重新出现了,但是与丰富内容页面之间存在很大的差距,因为可见性并不会物理上删除页面中的内容,而仅仅是可见性。

I then researched some more and discovered the .height() call in jQuery and decided to try to employ it. 然后,我进行了更多研究,并在jQuery中发现了.height()调用,并决定尝试使用它。 It worked. 有效。 I was able to call height() to crush down the div and then reexpand it to fit the current content. 我能够调用height()来粉碎div,然后将其重新展开以适合当前内容。

I was thrilled to see this work in both FF and Chrome but then I opened it in IE8. 我很高兴在FF和Chrome中都能看到此功能,但是后来我在IE8中打开了它。 Nothing. 没有。 The giant gap was still there. 巨大的差距仍然存在。 Crestfallen I once again turned to the internet and discovered that it was because I was lacking the standard DOCTYPE call at the top of my page and so IE was running in Quirks mode. Crestfallen我再次转向互联网,发现那是因为我缺少页面顶部的标准DOCTYPE调用,所以IE以Quirks模式运行。 I made the change and bam, it worked. 我进行了更改,然后就成功了。

Now the fun part, this is actually intended to run in Facebook. 现在有趣的部分实际上是打算在Facebook中运行。 I already had some HTML in a php file from a test run and I swapped it out for this new code. 我已经通过测试运行在php文件中添加了一些HTML,然后将其换成新代码。 I opened up Chrome, FF, and IE and lo and behold Chrome and FF both work; 我打开了Chrome,FF和IE,然后打开了Chrome和FF,它们都工作了; IE, on the other hand, has the same old giant gap that I had just gotten rid of. 另一方面,IE具有我刚刚摆脱的旧的巨大差距。

The Question 问题
At this point I'm not sure what else to attempt. 在这一点上,我不确定还有什么尝试。 I was hoping that jQuery Tools Tabs or jQuery UI Tabs might be of some use but they both seem to destroy the content and reload it as well. 我希望jQuery工具选项卡或jQuery UI选项卡可能有用,但它们似乎都破坏了内容并重新加载了内容。 What I would be most happy with would be to create an interface that didn't require my resizing the divs like this but at this point I just want something functional to work off of. 我最满意的是创建一个不需要像这样调整div大小的接口,但是在这一点上,我只希望可以使用某些功能。

Is there any way to either make the resizing work or to make the tabs not destroy the content upon switching to one another? 是否有任何方法可以使调整大小工作或使选项卡在切换到另一选项时不破坏内容? If you look at various Facebook games some of them seem to have the tabbed interface behavior I'm looking for but I'm just not sure how to replicate it. 如果您查看各种Facebook游戏,其中一些似乎具有我正在寻找的选项卡式界面行为,但我不确定如何复制它。 Can anyone point me in a new direction or suggest a fix? 谁能指出我的新方向或提出解决方案?

This is from jQuery UI : 这是从jQuery UI

...my slider, Google Map, sIFR etc. not work when placed in a hidden (inactive) tab? ...我的滑块,Google Map,sIFR等在放置在隐藏(非活动)标签中时不起作用?

There's an easy workaround. 有一个简单的解决方法。 Use the off-left technique for hiding inactive tab panels. 使用左偏技术隐藏不活动的选项卡面板。 Eg in your style sheet replace the rule for the class selector ".ui-tabs .ui-tabs-hide" with 例如,在样式表中,将类选择器“ .ui-tabs .ui-tabs-hide”的规则替换为

.ui-tabs .ui-tabs-hide {
    position: absolute;
    left: -10000px;
}

And then hide tabs normally. 然后正常隐藏标签。

暂无
暂无

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

相关问题 我正在尝试创建XML和XSL,但它给我一个错误,我不知道该怎么办 - I am trying to create an XML and XSL, but it is giving me an error that I can't figure out what to do 如何创建一个键盘事件,让我只使用退格键和数字(在键盘和小键盘之上)? - How do I create a keyboard event that lets me only use the backspace and numbers (on top of keyboard and numpad)? 我怎么能用reduce来做到这一点? 我正在尝试没有成功 - how can i do this with reduce? I'm trying without success 为什么此循环不执行我可以手动执行的操作? - Why doesn't this loop do what I can do manually? 嘿,我正在尝试使 desc 下的这些链接可点击。 我不完全确定该怎么做,有人可以看一下吗? - Hey, I'm trying to make these links under desc clickable. I'm not entirely sure how to do it though, can someone take a look? 我正在尝试通过AJAX调用返回创建一个结果数组。 我怎么做? - I'm trying to create an array of results from my return on an AJAX call. How do I do that? 我正在尝试使用onclick事件在循环内部定义一个函数,但它不像我期望的那样工作。我该怎么办? - I'm trying to define a function inside of a loop using onclick event, but it doesn't work like I expect. What should I do differently? React Search - 我正在尝试创建一个过滤器,但它不起作用 - React Search - I'm trying to create a filter and it doesn't work 如果IE上不支持任何内容,我该怎么办? - What can I do if nothing is supported on IE? 我正在尝试使用jquery加载,但是在获取特定代码段时不允许使用脚本标签,该怎么办? - I am trying to use jquery load, but that doesn't allow script tags when getting a certain piece of code, what can I do?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM