javascript - 如何为我的案例创建响应式设计中的动画?

标签 javascript html css animation

我在 chrome 上有一个奇怪的错误,我需要你们的帮助。

我的应用需要响应式设计。’

item”的宽度会根据浏览器的宽度而改变。当 chrome 首次加载页面时,宽度会相应改变。但是,在我单击“item”并运行动画后,“item”的宽度将不再改变,即使我调整了浏览器的大小。我觉得这是 chrome 上的动画问题。它在 FF 中运行良好,但在 Chrome 中运行良好。有人有什么好的建议吗?非常感谢!

http://jsfiddle.net/7kvX2/3/

html

 <div id="wrapper">
     <div class='item'>test 1</div>
     <div class='item'>test 2</div>
     <div class='item'>test 3</div>
 </div>

CSS

.item{
    display:inline-block;
    background-color:yellow;
}

.open{
    -webkit-animation: openMenu 1s;
    animation:openMenu 1s;
}

.close{
    -webkit-animation: closeMenu 1s;
    animation:closeMenu 1s;
}

@media (min-width: 800px) and (max-width: 1000px) {
    .item{
        width:105px;
    }

    @-webkit-keyframes openMenu{
        from {width: 105px;}
        to   {width: 170px;}
    }

    @keyframes openMenu{
        from {width: 105px;}
        to   {width: 170px;}
    }

    @-webkit-keyframes closeMenu{
        from {width: 170px;}
        to   {width: 105px;}
    }
    @keyframes closeMenu{
        from {width: 170px;}
        to   {width: 105px;}
    }
}


@media (min-width: 400px) and (max-width: 800px) {
    .item{
        width:75px;
    }

    @-webkit-keyframes openMenu{
        from {width: 75px;}
        to   {width: 100px;}
    }

    @keyframes openMenu{
        from {width: 75px;}
        to   {width: 100px;}
    }

    @-webkit-keyframes closeMenu{
        from {width: 100px;}
        to   {width: 75px;}
    }
    @keyframes closeMenu{
        from {width: 100px;}
        to   {width: 75px;}
    }
}

js

$('.item').click(function(){
    if($(this).hasClass('open')){
        $(this).addClass('close').removeClass('open');

    }else{
        $(this).addClass('open').removeClass('close');
    }
})

最佳答案

fiddle :http://jsfiddle.net/7kvX2/4/

你的断点有点偏离,只有当你正好落在两者之间时才有效。

我删除了第一个媒体查询的上限:

@media (min-width: 800px){

并在第二个媒体查询中将下约束变小并将第二个参数设置为 799:

@media (min-width: 100px) and (max-width: 799px) {

关于javascript - 如何为我的案例创建响应式设计中的动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24266903/

相关文章:

php - 使用 curl php 上传缺少 POST 参数

javascript - 通过单击行将表行滚动到 div 的顶部

css - 在开发工具中一次性关闭所有 CSS 样式

javascript - 如何禁用 bsdatePicker 中的 future 日期

javascript - IE 9+ JQuery 拖放 div 不起作用

javascript - jQuery toggleClass 有效,在点击时添加 .text() 替换会破坏它

javascript - 为什么不能在 javascript 中使用 % 更改最大高度?

css - iphone4设备的尺寸是多少

javascript - 删除尾随零到小数点后 2 位

javascript - 使用jquery触发click事件动态添加href上的链接