javascript - 如何使用 jquery 从左到右或从右到左为 2 个 css 布局设置动画?

标签 javascript jquery html css slideshow

我的 jQuery 水平是业余的,现在我努力用幻灯片来解决这个问题,我知道如何使用变量进行淡出或淡入,但我不能从左到右或从右到左制作动画 2 种不同的布局与 next属性:

1.第一个布局是事件布局,display:block; 2.第二个布局(下一次按下按钮时显示的幻灯片/布局,但同时删除第一个布局)不是事件幻灯片,display:none;

这里我卡住了:

$('.next').click(function(){
var currentSlide=$('.active-slide');
var nextSlide=currentSlide.next();
currentSlide.removeClass('active-slide');
nextSlide.addClass('active-slide');
});

附加图片以提高可见性: image

更多信息的网站链接: Website

最佳答案

给你。 添加一个内部 div,例如:

<div class="slide1">
    <div class="slide-inner">
        ......
    </div>
</div>

CSS:

.slide-inner {
    left: 0;
    position: absolute;
    width: 100%;
}

.slide1 {
    overflow: hidden;
    position: relative;
}

jQuery:

jQuery(document).ready(function(){
    var totalWidth = 0;
    var select = jQuery('.slide1').find('.slide-inner > div');
    select.each(function(index) {
      totalWidth = +(totalWidth)+(+$(this).outerWidth(true));   
    });

    jQuery('.slide-inner').width(totalWidth);

    $('.next').click(function(){
        var currentSlide=$('.active-slide');
        var nextSlide=currentSlide.next();
        //currentSlide.removeClass('active-slide');
        //nextSlide.addClass('active-slide');

        // .position() uses position relative to the offset parent, 
        var pos = nextSlide.position();

        // .outerWidth() takes into account border and padding.
        var width = nextSlide.outerWidth();

        //show the menu directly over the placeholder
        jQuery('.slide-inner').animate({"left":(pos.left + width) + "px"}, "slow");
    });
});

关于javascript - 如何使用 jquery 从左到右或从右到左为 2 个 css 布局设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26744740/

相关文章:

javascript - 在类似于 jQuery 的 vanilla JS 中实现每个

javascript - 单击链接按钮时显示 Div

JavaScript 当单击选项卡 2 时,它将阻止 UI,但选项卡 1 必须处于事件状态

javascript - 如何在 TypeScript 中执行字符串插值?

javascript - 如何迭代数组中的数组

javascript - 在移动断点处用省略号或下拉菜单替换最左边的面包屑

javascript - 当我尝试将文件(图像)上传到服务器时出现错误 403

javascript - 在网页上截取 Adob​​e flash 播放器的屏幕截图

html - 根据背景反转文本颜色

HTML/CSS : 4 pixels of space