【问题标题】:JQuery animation is working differently in IE/Opera, Chrome, Firefox [closed]JQuery 动画在 IE/Opera、Chrome、Firefox 中的工作方式不同 [关闭]
【发布时间】:2014-01-27 04:14:03
【问题描述】:

我的图像动画在最新的 chrome 和 firefox 中无法正常运行,但在 IE8 和最新的 Opera 中运行良好

http://jsfiddle.net/wzHx3/7/ 和全屏示例http://dev.fama.net.pl/tides/ - 单击右侧三角形触发动画,然后单击左侧触发第二个动画

更新 - Chrome 中的第二个动画现在已修复为 afshin

更新 2 - 所有 Chrom 问题都已修复,感谢 afshin

问题 - Firefox:第一个动画比其他浏览器中的动画短,第二个动画之前是向右大跳转

Chrome、IE8 和 Opera 完美运行

JQUERY

$(window).load(function(){

    var speed = 500;
    var times = 2;
    var loop = setInterval(anim, 500);
    function anim(){
        times--;
        if(times === 0){clearInterval(loop);}
        $('#arrow-right').animate({right:-1,opacity:.2},speed).animate({right:-15, opacity:.5},speed);
    }
    anim(); 

    $('#bg img.pic').css('opacity','0');
});
$(document).ready(function(){

    var easing = 'easeInOutCubic';

$('#arrow-right').click(function(){
    $('#bg img.pic').animate({left:'0%', opacity: 1}, 2500, function() {
        $('#arrow-left').animate({left:0}, 800, easing);
    });
    $(this).animate({right:-125}, 800, easing);

});    

$('#arrow-left').click(function(){
    $('#bg img.pic').animate({left: '20%', opacity: 0}, 2500, easing, function() {
        $('#arrow-right').animate({right:-15}, 800, easing);
        //$(this).css('left','75%');
    });        
    $(this).animate({left:-125}, 800, easing);
});
});

CSS

* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }

body,html {
    overflow: hidden
}
#bg {
    position:fixed; 
    top:-50%; 
    left:-50%; 
    width:200%; 
    height:200%;
}
#bg img {
    position:absolute; 
    top:0; 
    left:0; 
    right:0; 
    bottom:0; 
    margin:auto; 
    min-width:50%;
    min-height:50%;
}
#bg img.blank {
    z-index: 0;
}
#bg img.pic {
    z-index: 1;
    left: 20%;
    opacity: 0;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
}
.arrow {
    position: absolute;
    top: 50%;
    margin-top: -120px;
    width: 0;
    height: 0;
    opacity:.5;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
    cursor: pointer;
    border-top: 120px solid transparent;
    border-bottom: 120px solid transparent;         
}
.arrow:hover {
    opacity:.2 !important;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)" !important;
}
#arrow-left {
    border-left: 120px solid #83bedd;
    left: -125px;
    z-index: 2;
}
#arrow-right {
    border-right: 120px solid #83bedd;
    right: -15px;
    z-index: 2;
}

HTML

<div id="bg">
    <img class="blank" src="http://dev.fama.net.pl/tides/img/bg.jpg" alt="" />
    <img class="pic" src="http://dev.fama.net.pl/tides/img/bga.jpg" alt="" />
</div>

<div id="arrow-left" class="arrow"></div>
<div id="arrow-right" class="arrow"></div>

【问题讨论】:

  • 似乎一切都很好,唯一的区别是动画的速度。可能你应该比动画更快地改变你的不透明度。问题只发生在 webkits 上。例如 safari - chrome 和 maxthon。
  • “跳跃”很可能是由于使用margin: auto 使图像居中所致。将margin: auto 更改为margin-top: automargin: bottom: auto 为我停止了跳跃:jsfiddle.net/wzHx3/2
  • @My Head Hurts your way 有助于 Firefox THX :] 但不适用于 webkits
  • @gidzior 是$('#bg img.pic').animate 中的-1,将其更改为0 为我消除了webkit 问题:jsfiddle.net/wzHx3/3
  • 对我也是如此,但设置 margin-top: auto 和 margin: bottom: auto 不起作用,这导致 img 不再缩放,因此无法解决 firefox 问题

标签: javascript jquery html css cross-browser


【解决方案1】:

看看这个也许有帮助

$('#arrow-right').click(function(){
    $('#bg img.pic').animate({left:'0%', opacity: 1}, 2500, function() {
        $('#arrow-left').animate({left:0}, 800, easing);
    });
    $(this).animate({right:-125}, 800, easing);

});    

$('#arrow-left').click(function(){
    $('#bg img.pic').animate({left: 20+'%', opacity: 0}, 2500, easing, function() {
        $('#arrow-right').animate({right:-15}, 800, easing);
        //$(this).css('left','75%');
    });        
    $(this).animate({left:-125}, 800, easing);
});

jsFiddle

【讨论】:

  • 你的方式消除了 webkit 中第二个动画中的一个小跳跃,谢谢
  • 但第一个动画仍然比其他浏览器短得多
  • @gidzior 我改了答案看看。
  • 呵呵呵呵是的,它正在修复 webkit 的问题,但现在 Firefox 中的第一个动画与 webkit 中的相同,所以它很短,在第二个动画仍然是一个跳转之前
  • 在 Firefox 中,在非常小的窗口(例如 600x600)中是可以的,但是当窗口较大时,动画会被破坏
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
  • 2014-08-28
  • 2016-01-28
  • 2011-01-25
  • 1970-01-01
相关资源
最近更新 更多