3

シナリオ:Chrome v51.0.2704、ブートストラップv2.3.2、Windows 10 v1511以下のスニペットを参照してください。私はこのケースに当てはまらないブートストラップCSSを除外しました。(Twitter)ホバーでブートストラップボタン入力が点滅する

問題点:マウスを素早く要素のオンとオフに移動させると、背景がわずかに明るい水平線でランダムに「ちらつき」するように見えます。

これは、Firefox v46、IE v11、またはEdge v25では発生していないようです。

button, 
 
input, 
 
select, 
 
textarea { 
 
    margin: 0; 
 
    font-size: 100%; 
 
    vertical-align: middle; 
 
} 
 

 
button, 
 
input { 
 
    *overflow: visible; 
 
    line-height: normal; 
 
} 
 

 
button::-moz-focus-inner, 
 
input::-moz-focus-inner { 
 
    padding: 0; 
 
    border: 0; 
 
} 
 

 
button, 
 
html input[type="button"], 
 
input[type="reset"], 
 
input[type="submit"] { 
 
    cursor: pointer; 
 
    -webkit-appearance: button; 
 
} 
 

 
label, 
 
select, 
 
button, 
 
input[type="button"], 
 
input[type="reset"], 
 
input[type="submit"], 
 
input[type="radio"], 
 
input[type="checkbox"] { 
 
    cursor: pointer; 
 
} 
 

 
label, 
 
input, 
 
button, 
 
select, 
 
textarea { 
 
    font-size: 14px; 
 
    font-weight: normal; 
 
    line-height: 20px; 
 
} 
 

 
input, 
 
button, 
 
select, 
 
textarea { 
 
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 
 
} 
 

 
input, 
 
textarea, 
 
.uneditable-input { 
 
    width: 206px; 
 
} 
 

 
input[type="file"], 
 
input[type="image"], 
 
input[type="submit"], 
 
input[type="reset"], 
 
input[type="button"], 
 
input[type="radio"], 
 
input[type="checkbox"] { 
 
    width: auto; 
 
} 
 

 
input:-moz-placeholder, 
 
textarea:-moz-placeholder { 
 
    color: #999999; 
 
} 
 

 
input:-ms-input-placeholder, 
 
textarea:-ms-input-placeholder { 
 
    color: #999999; 
 
} 
 

 
input::-webkit-input-placeholder, 
 
textarea::-webkit-input-placeholder { 
 
    color: #999999; 
 
} 
 

 
input, 
 
textarea, 
 
.uneditable-input { 
 
    margin-left: 0; 
 
} 
 

 
.btn { 
 
    display: inline-block; 
 
    *display: inline; 
 
    padding: 4px 12px; 
 
    margin-bottom: 0; 
 
    *margin-left: .3em; 
 
    font-size: 14px; 
 
    line-height: 20px; 
 
    color: #333333; 
 
    text-align: center; 
 
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75); 
 
    vertical-align: middle; 
 
    cursor: pointer; 
 
    background-color: #f5f5f5; 
 
    *background-color: #e6e6e6; 
 
    background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6); 
 
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6)); 
 
    background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6); 
 
    background-image: -o-linear-gradient(top, #ffffff, #e6e6e6); 
 
    background-image: linear-gradient(to bottom, #ffffff, #e6e6e6); 
 
    background-repeat: repeat-x; 
 
    border: 1px solid #cccccc; 
 
    *border: 0; 
 
    border-color: #e6e6e6 #e6e6e6 #bfbfbf; 
 
    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); 
 
    border-bottom-color: #b3b3b3; 
 
    -webkit-border-radius: 4px; 
 
    -moz-border-radius: 4px; 
 
      border-radius: 4px; 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe6e6e6', GradientType=0); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(enabled=false); 
 
    *zoom: 1; 
 
    -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); 
 
    -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); 
 
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); 
 
} 
 

 
.btn:hover, 
 
.btn:focus, 
 
.btn:active, 
 
.btn.active, 
 
.btn.disabled, 
 
.btn[disabled] { 
 
    color: #333333; 
 
    background-color: #e6e6e6; 
 
    *background-color: #d9d9d9; 
 
} 
 

 
.btn:first-child { 
 
    *margin-left: 0; 
 
} 
 

 
.btn:hover, 
 
.btn:focus { 
 
    color: #333333; 
 
    text-decoration: none; 
 
    background-position: 0 -15px; 
 
    -webkit-transition: background-position 0.1s linear; 
 
    -moz-transition: background-position 0.1s linear; 
 
     -o-transition: background-position 0.1s linear; 
 
      transition: background-position 0.1s linear; 
 
} 
 

 
.btn-large { 
 
    padding: 11px 19px; 
 
    font-size: 17.5px; 
 
    -webkit-border-radius: 6px; 
 
    -moz-border-radius: 6px; 
 
      border-radius: 6px; 
 
} 
 

 
.btn-primary { 
 
    color: #ffffff; 
 
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); 
 
    background-color: #006dcc; 
 
    *background-color: #0044cc; 
 
    background-image: -moz-linear-gradient(top, #0088cc, #0044cc); 
 
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc)); 
 
    background-image: -webkit-linear-gradient(top, #0088cc, #0044cc); 
 
    background-image: -o-linear-gradient(top, #0088cc, #0044cc); 
 
    background-image: linear-gradient(to bottom, #0088cc, #0044cc); 
 
    background-repeat: repeat-x; 
 
    border-color: #0044cC#0044cC#002a80; 
 
    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0044cc', GradientType=0); 
 
    filter: progid:DXImageTransform.Microsoft.gradient(enabled=false); 
 
} 
 

 
.btn-primary:hover, 
 
.btn-primary:focus, 
 
.btn-primary:active, 
 
.btn-primary.active, 
 
.btn-primary.disabled, 
 
.btn-primary[disabled] { 
 
    color: #ffffff; 
 
    background-color: #0044cc; 
 
    *background-color: #003bb3; 
 
} 
 

 
button.btn, 
 
input[type="submit"].btn { 
 
    *padding-top: 3px; 
 
    *padding-bottom: 3px; 
 
} 
 

 
button.btn::-moz-focus-inner, 
 
input[type="submit"].btn::-moz-focus-inner { 
 
    padding: 0; 
 
    border: 0; 
 
} 
 

 
button.btn.btn-large, 
 
input[type="submit"].btn.btn-large { 
 
    *padding-top: 7px; 
 
    *padding-bottom: 7px; 
 
}
<input type="submit" name="submit" class="btn btn-primary btn-lg">

+0

遷移が非常に速い(0.1秒)ので、ユーザーがそれほど敏感でないので、この効果を除去することをお勧めします。特に、この効果は、ボタンをホバリングするときには必要ありません。したがって、.btn:hover、.btn:からの遷移を削除することができます。これは、css: '.btn:hover、.btn:focus {transition-duration:0;}'で上書きします。私はこれが本当の解決策ではないことは承知していますが、もしあなたがそれをテストすれば、大きな違いは見られません! –

答えて

3

Fiddle

ここでの主な問題は、background-positioncan have bad performanceのアニメーションということです。代わりにbackground-position Iセットアップtransform: translateY(-15px)を使用してアニメーション化されて別々のdivをアニメーションの

ソリューション

なぜそれほど多くdiv

(あなただけの<button></button>を使用してtransformアニメーションで:afterをアニメーションでdiv秒の数を減らすことだと思うかもしれませんが、Chromeはあなたがtransitionoverflow: hiddenを持ってすることはできませんa bugを持ち、そしてborder-radiusが要素に正しく適用this SO questionに記載されている)。

なぜtransformを使用しますか? - この質問から元のちらつきがあるため発見することが困難な場合が

(本当に助けにズーム)

  • More Obvious Flicker:以下JSFiddlesをチェックアウト何が起こっているの経験を助けるために

アニメーションだけが0.1sになるので、私はそれを遅くしました3s

  • Color Contrast - 青色のバリエーションから色を変更すると、アニメーションにジッタがある理由がわかります。この例では、赤い部分がボタンの上に移動する直前に、黄色のスライバーがあることがわかります。これは私が元の質問で白いちらつきを見る理由についての私の推測です。
  • Fix (with color) - これは、元の色とアニメーションの速度
  • 完全なコード

    を復元する - この例では、アニメーションが原因 transform: translateY(-15px)
  • Final Answerを使用するのではスムーズに動いていることをはっきりと見ることができます

    button, 
     
    input, 
     
    select, 
     
    textarea { 
     
        margin: 0; 
     
        font-size: 100%; 
     
        vertical-align: middle; 
     
    } 
     
    
     
    button, 
     
    input { 
     
        *overflow: visible; 
     
        line-height: normal; 
     
    } 
     
    
     
    button::-moz-focus-inner, 
     
    input::-moz-focus-inner { 
     
        padding: 0; 
     
        border: 0; 
     
    } 
     
    
     
    button, 
     
    html input[type="button"], 
     
    input[type="reset"], 
     
    input[type="submit"] { 
     
        cursor: pointer; 
     
        -webkit-appearance: button; 
     
    } 
     
    
     
    label, 
     
    select, 
     
    button, 
     
    input[type="button"], 
     
    input[type="reset"], 
     
    input[type="submit"], 
     
    input[type="radio"], 
     
    input[type="checkbox"] { 
     
        cursor: pointer; 
     
    } 
     
    
     
    label, 
     
    input, 
     
    button, 
     
    select, 
     
    textarea { 
     
        font-size: 14px; 
     
        font-weight: normal; 
     
        line-height: 20px; 
     
    } 
     
    
     
    input, 
     
    button, 
     
    select, 
     
    textarea { 
     
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 
     
    } 
     
    
     
    input, 
     
    textarea, 
     
    .uneditable-input { 
     
        width: 206px; 
     
    } 
     
    
     
    input[type="file"], 
     
    input[type="image"], 
     
    input[type="submit"], 
     
    input[type="reset"], 
     
    input[type="button"], 
     
    input[type="radio"], 
     
    input[type="checkbox"] { 
     
        width: auto; 
     
    } 
     
    
     
    input:-moz-placeholder, 
     
    textarea:-moz-placeholder { 
     
        color: #999999; 
     
    } 
     
    
     
    input:-ms-input-placeholder, 
     
    textarea:-ms-input-placeholder { 
     
        color: #999999; 
     
    } 
     
    
     
    input::-webkit-input-placeholder, 
     
    textarea::-webkit-input-placeholder { 
     
        color: #999999; 
     
    } 
     
    
     
    input, 
     
    textarea, 
     
    .uneditable-input { 
     
        margin-left: 0; 
     
    } 
     
    
     
    
     
    
     
    
     
    .btn { 
     
        display: inline-block; 
     
        *display: inline; 
     
        padding: 4px 12px; 
     
        margin-bottom: 0; 
     
        *margin-left: .3em; 
     
        font-size: 14px; 
     
        line-height: 20px; 
     
        color: #333333; 
     
        text-align: center; 
     
        text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75); 
     
        vertical-align: middle; 
     
        cursor: pointer; 
     
        /* 
     
        background-color: #f5f5f5; 
     
        *background-color: #e6e6e6; 
     
        background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6); 
     
        background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6)); 
     
        background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6); 
     
        background-image: -o-linear-gradient(top, #ffffff, #e6e6e6); 
     
        background-image: linear-gradient(to bottom, #ffffff, #e6e6e6); 
     
        background-repeat: repeat-x; 
     
        */ 
     
        border: 1px solid #cccccc; 
     
        *border: 0; 
     
        border-color: #e6e6e6 #e6e6e6 #bfbfbf; 
     
        border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); 
     
        border-bottom-color: #b3b3b3; 
     
        -webkit-border-radius: 4px; 
     
        -moz-border-radius: 4px; 
     
        border-radius: 4px; 
     
        filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe6e6e6', GradientType=0); 
     
        filter: progid: DXImageTransform.Microsoft.gradient(enabled=false); 
     
        *zoom: 1; 
     
        -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); 
     
        -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); 
     
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); 
     
    } 
     
    
     
    .btn:hover, 
     
    .btn:focus, 
     
    .btn:active, 
     
    .btn.active, 
     
    .btn.disabled, 
     
    .btn[disabled] { 
     
        color: #333333; 
     
        /* 
     
        background-color: #e6e6e6; 
     
        *background-color: #d9d9d9; 
     
        */ 
     
    } 
     
    
     
    .btn:first-child { 
     
        *margin-left: 0; 
     
    } 
     
    
     
    .btn:hover, 
     
    .btn:focus { 
     
        color: #333333; 
     
        text-decoration: none; 
     
        /* Removed 
     
        background-position: 0 -15px; 
     
        -webkit-transition: background-position 3s linear; 
     
        -moz-transition: background-position 3s linear; 
     
         -o-transition: background-position 3s linear; 
     
          transition: background-position 3s linear; 
     
        */ 
     
    } 
     
    
     
    .btn-large { 
     
        padding: 11px 19px; 
     
        font-size: 17.5px; 
     
        -webkit-border-radius: 6px; 
     
        -moz-border-radius: 6px; 
     
        border-radius: 6px; 
     
    } 
     
    
     
    .btn-primary { 
     
        color: #ffffff; 
     
        text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); 
     
        /* 
     
        background-color: #006dcc; 
     
        *background-color: #0044cc; 
     
        background-image: -moz-linear-gradient(top, #0088cc, #0044cc); 
     
        background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc)); 
     
        background-image: -webkit-linear-gradient(top, #0088cc, #0044cc); 
     
        background-image: -o-linear-gradient(top, #0088cc, #0044cc); 
     
        background-image: linear-gradient(to bottom, #0088cc, #0044cc); 
     
        background-repeat: repeat-x; 
     
        */ 
     
        border-color: #0044cC#0044cC#002a80; 
     
        border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25); 
     
        filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc', endColorstr='#ff0044cc', GradientType=0); 
     
        filter: progid: DXImageTransform.Microsoft.gradient(enabled=false); 
     
    } 
     
    
     
    .btn-primary:hover, 
     
    .btn-primary:focus, 
     
    .btn-primary:active, 
     
    .btn-primary.active, 
     
    .btn-primary.disabled, 
     
    .btn-primary[disabled] { 
     
        color: #ffffff; 
     
        /*background-color: #0044cc; 
     
        *background-color: #003bb3; 
     
        */ 
     
    } 
     
    
     
    button.btn, 
     
    input[type="submit"].btn { 
     
        *padding-top: 3px; 
     
        *padding-bottom: 3px; 
     
    } 
     
    
     
    button.btn::-moz-focus-inner, 
     
    input[type="submit"].btn::-moz-focus-inner { 
     
        padding: 0; 
     
        border: 0; 
     
    } 
     
    
     
    button.btn.btn-large, 
     
    input[type="submit"].btn.btn-large { 
     
        *padding-top: 7px; 
     
        *padding-bottom: 7px; 
     
    } 
     
    
     
    
     
    /* New Styles */ 
     
    .btn-container { 
     
        overflow: hidden; 
     
        display: inline-block; 
     
        position: relative; 
     
    } 
     
    
     
    .background { 
     
        content: ""; 
     
        background-color: #0044cc; 
     
        position: absolute; 
     
        bottom: -15px; 
     
        left: 0; 
     
        right: 0; 
     
        width: 100%; 
     
        height: 45px; 
     
        z-index: -1; 
     
        background-image: linear-gradient(to bottom, #0088cc 0%, #0044cc 66%, #0044cc 66%, #0044cc 100%); 
     
        background-repeat: repeat-x; 
     
    } 
     
    
     
    .btn-container:hover .background { 
     
        transform: translateY(-15px); 
     
        -webkit-transition: transform 0.1s linear; 
     
        -moz-transition: transform 0.1s linear; 
     
        -o-transition: transform 0.1s linear; 
     
        transition: transform 0.1s linear; 
     
    } 
     
    
     
    .btn { 
     
        background-color: transparent; 
     
    } 
     
    
     
    .mask { 
     
        position: absolute; 
     
        margin: 0 auto; 
     
        overflow: hidden; 
     
        height: 30px; 
     
        z-index: 9; 
     
        top: 0px; 
     
        left: 0; 
     
        right: 0; 
     
        width: 100%; 
     
    } 
     
    
     
    .mask:after { 
     
        content: ''; 
     
        position: absolute; 
     
        left: 0; 
     
        top: 0; 
     
        border-radius: 4px; 
     
        width: 100%; 
     
        height: 100%; 
     
        box-shadow: 0px 0px 0px 2000px #f3f5f6; 
     
    }
    <div class="btn-container"> 
     
        <button class="btn btn-primary btn-lg"> 
     
        Submit 
     
        </button> 
     
        <div class="mask"> 
     
        </div> 
     
        <div class="background"> 
     
        </div> 
     
    </div>

  • +0

    これはホバー上の暗いbkgを取得するために使用します。私が期待していたものよりはるかにいっぱいで教育的な説明だった。あなただけでなく、_why_も説明しました。ありがとうございました! – PaulC

    +0

    恐ろしい、それは助けてうれしい! – adriancarriger

    2

    問題がホバー上のバックグラウンド位置です。 (-8pxから-14pxまでの任意の値が動作するはずです)が第2の値がちらつきを修正する必要があります削減:

    .btn:hover, 
    .btn:focus { 
        background-position: 0 -14px; 
    } 
    
    +0

    私は、デフォルトの-15pxの代わりに他の多くの値も使えることを発見しました!例えば、.btn:hover、.btn:focus {バックグラウンド位置:0 -18px;} 'または' ... background-position:0 -25px; ' –

    関連する問題