سؤال

أحاول أن أجري نص SIFR عند تحوم على DIV، مع بعض التأخير.

العلامة هي مثل هذا، عدة مرات:

<div class="box">
    <div class="text">

        <h6>sIFR Text</h6>

    </div>
</div>

هذا الرمز يقوم بالحيلة (من الاختباء إلى SIFR على تحوم)، ولكن دون تأخير:

$(document).ready(function() {      

        $('.text').hide();

        $('.box').mouseover(

        function() {

                $(this).children('.text').show();

                //sIFR code :
                    sIFR.replace(rockwell, {
                          selector: 'h6',
                         css: [
                            '.sIFR-root { color:#FFFFFF; font-size: 1.2em; text-transform: uppercase }',
                            'a {color: #333333; text-decoration: none;}',
                            'a:hover {color: #333333;text-decoration:underline;}'
                            ], wmode: "transparent"
                    }
                    ); //sIFR ends

        });



        $('.box').mouseout(

        function() {
                $(this).children('.text').hide();
            }
    );
});

حاولت استخدام البرنامج المساعد الهادئ، وتحميله، واستخدامه مثل هذا، لكن لا يبدو أنه يعمل:

$(document).ready(function() {        

        $('.text').hide();

        $('.box').hoverIntent(

                function() {

                    $(this).children('.text').show();

        //sIFR code should go here
                    sIFR.replace(rockwell, {
                          selector: 'h6',
                         css: [
                            '.sIFR-root { color:#FFFFFF; font-size: 1.2em; text-transform: uppercase }',
                            'a {color: #333333; text-decoration: none;}',
                            'a:hover {color: #333333;text-decoration:underline;}'
                            ], wmode: "transparent"
                    }
                    ); //sIFR ends

                },

                function(){

                    $(this).children('.text').hide();

                    }
       );

});

هل يمكنك الإشارة إلى أي بديل؟ ربما يكون Settimeout بديلا جيدا، لكنني استخدمه من قبل، وأنا لست متأكدا حقا أين يجب أن أضعها.

شكرا لأي طرف.

هل كانت مفيدة؟

المحلول

يمكنك استخدام pettimeout.

$(document).ready(function() {          

        //delcare a variable to hold the timeout
        var to;

        $('.text').hide();

        $('.box').mouseover(

                function() {

                  $(this).children('.text').show();

                  // do sIFR code after 1000 milliseconds
                  to = setTimeout(function () { /* sIFR code goes here */ }, 1000);

                });



        $('.box').mouseout(

                function() {
                        // If mouseout happens before the delay ends 
                        // you probably don't want sIFR code to run.
                        clearTimeout(to);


                        $(this).children('.text').hide();
                }
        );
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top