简体   繁体   English

如何向此脚本添加平滑过渡

[英]How do I add smooth transitions to this script

How do I add smooth transitions when display block and hide: 在显示块和隐藏时如何添加平滑过渡:

$(document).ready(function(){
    $(".userBox").mouseover(function () {
        $(this).find('.inBox').css({ display: "block" });
        $(this).find('.boxDisc').css({ display: "block" });
    $(".userBox").mouseout(function () {
        $(this).find('.inBox').css('display', 'none');
        $(this).find('.boxDisc').css('display', 'none');
    });
  });
});

Because right now it's instant and doesn't look good. 因为现在它是即时的,而且看起来不太好。 Thanks! 谢谢!

One way is to use jQuery fading methods : 一种方法是使用jQuery淡入淡出方法

$(document).ready(function () {
    $(".userBox").mouseover(function () {
        $(this).find('.inBox').stop().fadeIn('fast');
        $(this).find('.boxDisc').stop().fadeIn('fast');
        $(".userBox").mouseout(function () {
            $(this).find('.inBox').stop().fadeOut('fast');
            $(this).find('.boxDisc').stop().fadeOut('fast');
        });
    });
});

Example: 例:

http://jsfiddle.net/L9t4J/ http://jsfiddle.net/L9t4J/

You could try fadeIn and fadeOut: 您可以尝试fadeIn和fadeOut:

$(document).ready(function(){
    $(".userBox").mouseover(function () {
        $(this).find('.inBox').fadeIn(500);
        $(this).find('.boxDisc').fadeIn(500);
    $(".userBox").mouseout(function () {
        $(this).find('.inBox').fadeOut(500);
        $(this).find('.boxDisc').fadeOut(500);
    });
  });
});

using jQuery methods such as show('slow') , hide('slow') , toggle('slow') will make transitions smoother. 使用show('slow')hide('slow')toggle('slow')等jQuery方法将使过渡更加平滑。

http://api.jquery.com/show/ http://api.jquery.com/show/

http://api.jquery.com/hide/ http://api.jquery.com/hide/

http://api.jquery.com/toggle/ http://api.jquery.com/toggle/

Other useful, playful and great methods are .animate() and jQuery ui's slide effects ( https://api.jqueryui.com/slide-effect/ ) 其他有用,有趣且出色的方法是.animate()和jQuery ui的幻灯片效果( https://api.jqueryui.com/slide-effect/

Cheers! 干杯!

Edit: I was going to write about the fadeIn and fadeOut methods too. 编辑:我也要写有关fadeIn和fadeOut方法的文章。 But Maurice Perry was quicker to point those out with an example :) 但是,莫里斯·佩里(Maurice Perry)更快地举例说明了这些问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM