JQuery: Как я получаю Hoverintent как эффект, работающий с mousenter / mouseleave? Ниже:

$(document).ready(function () {
    $('.viewport').mouseenter(function (e) {
        $(this).css({
            'z-index': '10'
        }); /*Add a higher z-index value so this image stays on top*/
        $(this).children('a').children('img').animate({
            height: '300',
            left: '-40',
            top: '-40',
            width: '300',
        }, 300);
        $(this).children('a').children('span').fadeIn(280);;
    }).mouseleave(function (e) {
        $(this).css({
            'z-index': '0'
        }); /* Set z-index back to 0 */
        $(this).children('a').children('img').animate({
            height: '225',
            left: '0',
            top: '-0',
            width: '225',
        }, 250);
        $(this).children('a').children('span').fadeOut(280);
    });
});
1
задан Reigel 18 July 2010 в 01:57
поделиться

2 ответа

use setTimeout

simple demo

$(document).ready(function () {
    var hoverIntent;

    $('.viewport').mouseenter(function (e) {
        clearInterval(hoverIntent);
        $this = $(this); // save reference of $(this)
        hoverIntent = setTimeout(function () {
            $this.css({
                'z-index': '10'
            }); /*Add a higher z-index value so this image stays on top*/
            $this.children('a').children('img').animate({
                height: '300',
                left: '-40',
                top: '-40',
                width: '300',
            }, 300);
            $this.children('a').children('span').fadeIn(280);
        }, 500);
    }).mouseleave(function (e) {
        clearInterval(hoverIntent);
        $(this).css({
            'z-index': '0'
        }); /* Set z-index back to 0 */
        $(this).children('a').children('img').animate({
            height: '225',
            left: '0',
            top: '-0',
            width: '225',
        }, 250);
        $(this).children('a').children('span').fadeOut(280);
    });
});
2
ответ дан 2 September 2019 в 22:57
поделиться

Вот ответ:

<script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
        $(".viewport ").hoverIntent(makeTall,makeShort);

    }); // close document.ready

    function makeTall(){  $(this).find('img').animate({ height: '300', left: '-40', top: '-40', width: '300',}, 300); $(this).find('span').fadeIn(280);}
    function makeShort(){ $(this).find('img').animate({ height: '225',left: '0', top: '-0'  , width: '225' ,}, 300);$(this).find('span').fadeOut(280);}
</script>
0
ответ дан 2 September 2019 в 22:57
поделиться
Другие вопросы по тегам:

Похожие вопросы: