简体   繁体   English

如何使用jQuery向我的网站添加滑块过渡?

[英]How would I add a slider transition to my website with jQuery?

I am using the jQuery library so that is available. 我正在使用jQuery库,因此可用。 I need to know how to add a sliding effect to this page: 我需要知道如何在此页面上添加滑动效果:

http://qasim.x10.mx/iqbal/ http://qasim.x10.mx/iqbal/

Notice when you click it, it fades in and out, but I would much rather love it to slide, I have a small idea on how they work but, in the way it is currently coded, but not sure the proper technique in implementing one. 请注意,当您单击它时,它会淡入淡出,但我更喜欢它滑动,我对它们的工作方式并不了解,但是,以当前编码的方式,但不确定实现它的正确技术。 what could be the easiest way? 最简单的方法是什么?

Many thanks. 非常感谢。

As I understand your site, you have this code that does the fading transition: 据我了解您的网站,您可以使用以下代码进行渐隐式转换:

$('nav ul li').not('#line').click(function(){
    selected = $(this).attr('id');
    $('nav ul li').css({'background': '', 'color': '#999'});
    $(this).css({'background': getColor(selected), 'color': '#FFF'});

    $('.content').fadeOut('fast', function(){
        $(this).html($('div#'+selected).html());
        $(this).fadeIn('fast');
    })

})

If you wanted it to slide, it'd probably be easier to use jQuery UI. 如果您希望它滑动,则使用jQuery UI可能会更容易。 If you want something like to slide and fade off to the left, then you could use the drop transition in jQuery UI to accomplish this: 如果您想要向左滑动和渐隐,则可以使用jQuery UI中的放置过渡来完成此操作:

$('nav ul li').not('#line').click(function(){
    selected = $(this).attr('id');
    $('nav ul li').css({'background': '', 'color': '#999'});
    $(this).css({'background': getColor(selected), 'color': '#FFF'});

    $('.content').hide('drop', {direction: 'left'}, 'fast', function(){
        $(this).html($('div#'+selected).html());
        $(this).show('drop', {direction: 'right'}, 'fast');
    })

})

I obviously didn't try running this exact code on your site, but it will definitely look something like that. 我显然没有尝试在您的网站上运行此确切的代码,但是肯定看起来像这样。

You can find out more about the drop effect here: 您可以在此处找到有关下降效果的更多信息:

Hopefully this helps. 希望这会有所帮助。 :) :)

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

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