0

私は Javascript の初心者です。jquery を使用して列の高さを変更するテンプレートを使用しています。javascript コードは単純な index.html ページでうまく機能しますが、それを joomla 3 で使用すると、jQuery 関数は実行されません。だから私は追加しました:

  • 「jQuery.noConflict();」
  • すべての $ を jQuery に置き換えます

それでも高さはサイズ変更されません。

コードの下:

    jQuery.noConflict();
// JavaScript Document
jQuery(window).load(function () {



    var winWidth = jQuery(window).width()

            if (winWidth > 767){

                // To ensure that the sidebar sticks to the bottom of the page
                // we calculate the height of the tallest object and match the
                // sidebar to it.

                var height1 = jQuery('.eightcol').height()
                var height2 = jQuery('html').height()
                var height3 = jQuery("#sidebar-container").height()
                var height4 = jQuery(window).height()

                /*  Tab Shortcode Fix
                    Because all tabbed content loads stacked this throws off
                    the height of the .eightcol and html elements so we need to subtract 
                    the extra height added by the stacked tabbed content. Once we have that
                    we can reset the hight values of html and .eightcol correctly. We will
                    need to figure out the tallest of all the tabbed content elements
                    and add that back into the total height of .eightcol and html

                    ONLY do this if we are using the tab shortcode.
                */
                if (jQuery('.tabcontent').length) {
                    var max = 0;
                    var numtotal = 0;
                    // Loop through all .tabcontent classes and get the tallest tab.
                    jQuery('.tabcontent').each(function(){
                        var num = jQuery(this).height()
                        // Track total height of all tabs so we can subtract later
                        numtotal = numtotal + num;
                        if(num > max)
                        {
                           max = num;
                        }
                    });

                    // Substract the total height of all .tabcontent from .eightcol and html
                    // then add in only the lattest .tabcontent.
                    height1 = height1 - numtotal;
                    height1 = height1 + max;

                    height2 = height2 - numtotal;
                    height2 = height2 + max;

                };



                // Function to get the Max value in Array
                Array.max = function( array ){
                return Math.max.apply( Math, array );
                };

                var maxheight = Array.max([height1,height2,height3,height4])


                if (height3 < maxheight) {
                    //jQuery("#sidebar").height(maxheight)
                    jQuery("#sidebar").css('height', maxheight + 'px');
                }

            }else{
                jQuery("#sidebar").css("height","auto")
            }   

    jQuery(window).resize(function() {

            var winWidth = jQuery(window).width()

            if (winWidth > 767){

                var height1 = jQuery('.eightcol').height()
                var height2 = jQuery('html').height()
                var height3 = jQuery("#sidebar-container").height()
                var height4 = jQuery(window).height()




                // Function to get the Max value in Array
                Array.max = function( array ){
                return Math.max.apply( Math, array );
                };

                var maxheight = Array.max([height1,height2,height3,height4])

                //console&&console.log('maxheight ' + maxheight);

                if (height3 < maxheight) {
                    jQuery("#sidebar").css('height', maxheight + 'px');
                }
            }else{
                    jQuery("#sidebar").css("height","auto")
            }

       });

}); 

jQuery(document).ready(function(){
            var height3 = jQuery("#sidebar-container").height()
        });

私はそれを正しくやっていますか?うまくいかない理由はありますか?

ありがとうございました

4

1 に答える 1

0

正確に何を達成しようとしていますか?Twitter Bootstrap を実装した Protostar テンプレートにはうんざりしています。そこから始めて、index.php ページをよく見て、グラフィカル テンプレートを確認することを強くお勧めします。最後に動的テストを実行し、ブラウザー ウィンドウを絞り込み、div がどこにあるかを確認します。いくつかの異なるスマートフォンでサイトをチェックしてください。などなど... 繰り返しますが、このプロジェクトはどこへ行くつもりですか?

注: 無料の Joomla 3 動的テンプレートには、クレイジーで不必要な複雑さが組み込まれているものがあります。テンプレート開発者を雇ってあなたを救済するしかないところまで疑いを持たない人を捕まえるために、そのように行われていると私は信じています。名前は言及されていません。Got ya! のフィッシュ フックのコンセプトのバーブに似ています。それが彼らのビジネスモデルです。

推奨事項: Protostar から始めて、div を再設計し、.less を使用してスタイル シートを作成し、これに沿って移動する方法を学びます...

于 2013-08-14T08:09:08.877 に答える