0

divこんにちは、jquery を使用して最大化および最小化したいと考えています。最大化および最小化するときに、クラスメソッドの削除と追加を使用します。しかし、すでに最大化されている場合、最小化することはできません。

ここに私のjqueryコードを示します:

$('.readmore').click(function (event) {
            event.preventDefault();
            $("#ry-new-content-3").animate({
                width : "+=460"
            },1000,function(){
                $('.more-content').slideDown('slow', function(){

                });
            });
            $(this).text($(this).text() == 'Read Less' ? 'Read More' : 'Read Less');

            if($(this).attr('class') == 'readmore') {
                $(this).removeClass();
                $(this).addClass('readless');
            }

         });

         $('.readless').click(function (event) {
            event.preventDefault();
            $('.more-content').slideUp('slow', function(){
                $("#ry-new-content-3").animate({
                    width : "-=460"
                },1000,function(){

                });
            });

         });

そして、それは私のHTMLコードです:

<div id="ry-new-content-3">
        <div class="scrollable-area-page">
            <div class="summary-content">
                <p>
                    The original Master piece was designed by the now famous JMP design group, a California based golf Design Company that has also designed the renowned Rainbow Hills Club & Royal Jakarta courses both located in Jakarta, along with over 70 international standard courses worldwide.
                    Overall Royal Sumatra could easily be rated as one of the most challenging and interesting layouts in all of Indonesia. To pinpoint a special feature of the Royal Sumatra layout is to mention many unique and eye pleasing holes that are spread out amongst the private Modern living cluster style housing estates and still natural forest land.
                </p>
            </div>
            <div class="more-content" style="display:none;">
                <p>
                    One of the concepts in the design was to spread the 18 holes out throughout the 254 hectare estate to not only allow privacy & safety for golfers but add more beautiful golf course views for home owners. Combined with the tropically landscape & buzzing wildlife in our environment including breath taking crystal clear morning views of famous Bukit Barisan & Brestagi Mountains, Royal Sumatra Golf and Country Club provides the strategic test & beautiful environment that every golfer wants and few golf clubs can offer.  
                    A variety of unique features await the avid golfer. Strategy is required at all times. Fairways are generous in size to accommodate the beginner, however undulating and strategically located white sand bunkers, creeks and large lakes add a stern test for the avid golfer to say the least Likely the most challenging feature of this championship layout are the multi tiered and  sloped putting greens which consistently run at fast speeds, to be fair these are arguably the most challenging greens in all of South East Asia. 
                </p>

                <p>
                    A fleet of new Club Car Buggies and 140+ uniformed female caddies complete the golfers every need and with prices all inclusive approximately USD $70 on weekends and USD $55 on weekdays ( Golf, Caddy, Buggy) Royal Sumatra is well worth it for the Golf traveler looking to truly test his golf game without damaging the bank balance. 
                </p>
            </div>
        </div>
        <div class="readmore">
            Read More
        </div>
    </div>

ありがとうございました。

4

1 に答える 1

1

jQuerys Toggleを試してみましたか? 私はあなたと同じことを何度も試しましたが、個人的な意見として、クラスの交換はそれだけの価値がないので、トグルまたは if ステートメントの使用を終了しました。例えば:

maximized = 500px
if($(".target").height() != maxmized){
   // maximize it
} else {
   // minimize it
}

また、すべてがどのように見えるかわからなくても、アニメーション時間を考慮したい場合があります。クリックが速すぎたり遅すぎたりすると、アクションが開始されない可能性があるため、コールバックを使用するとよいでしょう。

于 2013-11-13T13:10:38.830 に答える