【问题标题】:How to animate 2 css layouts from left to right or from right to left with jquery?如何使用jquery从左到右或从右到左为2个css布局设置动画?
【发布时间】:2014-11-04 20:48:45
【问题描述】:

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

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

【问题讨论】:

  • 向我们展示您的 html 和样式
  • 您是要以淡出方式滑动图像还是仅在大 div 中移动项目?
  • [link]sorfilm.byethost8.com 了解更多信息,我附上了链接页面。在大 div 中移动项目,但有 2 种不同的布局。

标签: javascript jquery html css slideshow


【解决方案1】:

给你。 添加一个内部 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");
    });
});

【讨论】:

  • 这行不通,也许你可以帮助我提供一个关于小提琴的视觉示例。谢谢
猜你喜欢
  • 1970-01-01
  • 2021-06-05
  • 2011-03-04
  • 1970-01-01
  • 2011-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多