【问题标题】:jQuery UI formating sections content when resizing browser调整浏览器大小时 jQuery UI 格式化部分内容
【发布时间】:2014-01-04 02:32:16
【问题描述】:

我正在使用自定义手风琴脚本,我遇到的问题是,在调整浏览器大小时,它会格式化其中一个部分的内容。我希望内容保持不变,并且如果您想查看内容,滚动条会很小心。在我的演示中,您将在第 3 部分看到问题。

我尝试做溢出:隐藏,但如果我在 ui 内容上做它会消除滚动条。我也做了 p 上隐藏的溢出,但仍然没有按我的意愿工作。提前致谢。

这里是my Demo

这是 HTML 代码:

<head>
    <meta charset="utf-8">

    <style type="text/css">body{font:62.5% Verdana,Arial,sans-serif}</style>
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
</head>
<body>

 <div class="file_wrapper">
        <div class="file_inner">

<h3><a href="#">Section 1</a></h3><div>
<span class="diff"><p>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p></span>
<p></p>
<p>##############################################################################</p>
<p># Test 1. </p>
<p># Test 2. </p>
<span class="diff"><p># Test 3. </p>
<p># Test 4. </p>
<p># Test 5. </p>
<p>##############################################################################</p>
            </span></div>
<h3><a href="#">Section 2</a></h3><div>
<span class="minus"><p>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p>
<p></p>
<p>##############################################################################</p>
<p># Test 1. </p>
<p># Test 2. </p>
<p># Test 3. </p>
<p># Test 4. </p>
<p># Test 5. </p>
<p>##############################################################################</p>
            </span></div>
<h3><a href="#">Section 3</a></h3><div>
<p>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p>
<p> </p>
<p>################################################################################</p>
<p># Test 1. GOOD *** Check up/up state for all interfaces excluding tunnel       #</p>
<p># Test 2. GOOD *** BGP neighbor not active                                     #</p>
<p># Test 3. GOOD *** BGP adv and routes check                                    #</p>
<p># Test 4. GOOD *** Show IP OSPF Neighbor                                       #</p>
<p># Test 5. GOOD *** GLBP tested correctly                                       #</p>
<p># Test 6. GOOD *** Verify WCCP is running correctly                            #</p>
<p># Test 7. GOOD *** All pings were succesful                                    #</p>
<p># Test 8. GOOD *** Environmental status                                        #</p>
<p>################################################################################</p>
            </div>                </div>                                                                                                    
              </div>
              </div>

      <div class="file_wrapper">

        <div class="file_inner">
<h3><a href="#">Section 1</a></h3><div>
<span class="diff"><p>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p></span>
<p></p>
<p>##############################################################################</p>
<p># Test 1. </p>
<p># Test 2. </p>
<span class="diff"><p># Test 3. </p>
<p># Test 4. </p>
<p># Test 5. </p>
<p>##############################################################################</p>
            </span></div>
<h3><a href="#">Section 2</a></h3><div>
<p>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p>
<p></p>
<p>##############################################################################</p>
<p># Test 1. </p>
<p># Test 2. </p>
<p># Test 3. </p>
<p># Test 4. </p>
<p># Test 5. </p>
<p>##############################################################################</p>
            </div>
<h3><a href="#">Section 3</a></h3><div>
<p>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p>
<p> </p>
<p>################################################################################</p>
<p># Test 1. GOOD *** Check up/up state for all interfaces excluding tunnel       #</p>
<p># Test 2. GOOD *** BGP neighbor not active                                     #</p>
<p># Test 3. GOOD *** BGP adv and routes check                                    #</p>
<p># Test 4. GOOD *** Show IP OSPF Neighbor                                       #</p>
<p># Test 5. GOOD *** GLBP tested correctly                                       #</p>
<p># Test 6. GOOD *** Verify WCCP is running correctly                            #</p>
<p># Test 7. GOOD *** All pings were succesful                                    #</p>
<p># Test 8. GOOD *** Environmental status                                        #</p>
<p>################################################################################</p>

                </div>                                                                                               
              </div>

</body>

这是我的 jQuery:

 /* $(function() {
            $( ".accordion" ).accordion();
            //$( "#accordion2" ).accordion();
        });
        */
       $(document).ready(function(){

           var $accordions = $('.file_inner');

           function accordion_expand_all()
           {
               var sections = $accordions.find("h3");
               sections.each(function(index, section){
                   if ($(section).hasClass('ui-state-default') && !$(section).hasClass('accordion-header-active')) {
                       $(section).click();
                   }
               });

           }

           /*
           function accordion_collapse_all()
           {
               var sections = $accordions.find("h3");
               sections.each(function(index, section){
                   if ($(section).hasClass('ui-state-active')) {
                       $(section).click();
                   }
               });
           }

             */


        $('.file_inner').accordion({
            active: true,
            beforeActivate: function(event, ui) {

                // The accordion believes a panel is being opened
                if (ui.newHeader[0]) {
                    var currHeader  = ui.newHeader;
                    var currContent = currHeader.next('.ui-accordion-content');
                    // The accordion believes a panel is being closed
                } else {
                    var currHeader  = ui.oldHeader;
                    var currContent = currHeader.next('.ui-accordion-content');
                }
                // Since we've changed the default behavior, this detects the actual status
                var isPanelSelected = currHeader.attr('aria-selected') == 'true';

                // Toggle the panel's header
                currHeader.toggleClass('ui-corner-all',isPanelSelected).toggleClass('accordion-header-active ui-state-active ui-corner-top',!isPanelSelected).attr('aria-selected',((!isPanelSelected).toString()));

                // Toggle the panel's icon
                currHeader.children('.ui-icon').toggleClass('ui-icon-triangle-1-e',isPanelSelected).toggleClass('ui-icon-triangle-1-s',!isPanelSelected);

                // Toggle the panel's content
                currContent.toggleClass('accordion-content-active',!isPanelSelected)
                if (isPanelSelected) { currContent.slideUp('fast'); }  else { currContent.slideDown('fast'); }


                var $this = $(this);

                if (!$this.hasClass('programatic')) {
                    var active = $this.children('.ui-accordion-content').index(ui.newPanel);
                    var $otherAccordions = $accordions.not($(this));

                    $otherAccordions.addClass('programatic');
                    $otherAccordions.accordion('option', 'active', active);
                    $otherAccordions.removeClass('programatic');
                }


                return false; // Cancels the default action
            }

        });
        accordion_expand_all()


       })

【问题讨论】:

    标签: javascript jquery html css jquery-ui


    【解决方案1】:

    你所能做的就是在 css 中尝试这样做:

    div{position:absolute;left:(somepixel)px;top:(somepixel)px;}
    

    基本上,如果您为根元素(即 html 文档)指定 width:100% 和 height:100%,它会根据可用宽度自动调整其大小。

    【讨论】:

    • 并且不要以百分比形式给出宽度和高度...调整浏览器大小时会产生一点麻烦
    • 尽量不要在正文中使用百分比 { color: #111;行高:1.5;边距:0 自动;填充:0;宽度:90%;高度:100%; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;背景:#f9f9f9; }
    • 但我希望页面调整我不想调整的内容是内容(第 3 节内的段落)
    猜你喜欢
    • 2012-02-23
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    相关资源
    最近更新 更多