[英]CSS hover animation not working
大家好,我對CSS懸停動畫有一個問題。 我創建了兩個演示:
第一個DEMO動畫效果很好。 但是seconde DEMO無法正常工作。
因此,在第二個演示中,您可以看到有兩個名稱,例如Paul和Rihanna。將鼠標懸停在Paul的名稱上時,將打開懸浮卡,但沒有動畫。 但是,如果您檢查了第一個演示,則可以看到動畫在其中運行。 任何人都可以幫助我在工作第二個演示(如第一個演示)時所缺少的東西。
AJAX:
var response = '<div class="p-tooltip"> <div class="profile-header"></div> <div class="profile-navigation"> <a href="http://kraigo.tumblr.com/" class="profile-action">Follow</a> <p class="profile-nick"> <a href="http://kraigo.tumblr.com/">Page Name</a> </p> </div> <div class="profile-ava"></div> <div class="profile-info"> <h1 class="profile-title">Username</h1> <p class="profile-description">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy ..</p> </div> <ul class="profile-items"> <li></li> <li></li> <li></li> </ul> </div>';
$(document).ready(function () {
function showProfileTooltip(e, id) {
//send id & get info from get_profile.php
$.ajax({
url: '/echo/html/',
data: {
html: response,
delay: 0
},
method: 'post',
success: function (returnHtml) {
e.find('.k-isim-wrp').html(returnHtml).promise().done(function () {
$('.kisi-isim').addClass('loaded');
});
}
});
}
function hideProfileTooltip() {
$('.kisi-isim').removeClass('loaded');
}
$('.kisi-isim').hover(function (e) {
var id = $(this).find('.k-isim').attr('data-id');
showProfileTooltip($(this), id);
}, function () {
hideProfileTooltip();
});
});
CSS
.k-isim {
float:left;
width:auto;
height:17px;
font-weight:bold;
position:relative;
z-index:0;
}
.kisi-isim{
float:left;
width:auto;
height:17px;
font-weight:bold;
position:relative;
}
.kisi-isim-mask {
width:130px;
position:relative;
z-index:1;
}
.loaded .kisi-isim-mask{
z-index:-1;
}
.profile-nnm {
width:auto;
height:17px;
display:block;
}
.k-isim a:hover:before{
content:'';
position:absolute;
display:block;
width:100%;
height:17px;
left:0;
z-index:2;
}
.p-tooltip {
position: absolute;
margin-top: 10px;
top: 100%;
left: 50%;
margin-left: -140px;
width: 280px;
max-height: 120px;
border-radius: 5px;
overflow: hidden;
background-color: #F0F0F0;
visibility: hidden;
opacity: 0;
transition: all 0.5s ease;
}
.profile-header {
height: 120px;
background-image: url(https://pbs.twimg.com/profile_banners/571038694/1395748220/1500x500);
background-size: auto 120px;
background-position: 50%;
}
.profile-navigation {
position: absolute;
top: 0;
left: 0;
padding: 10px;
width: 100%;
box-sizing: border-box;
}
.profile-nick {
color: #fff;
margin: 0;
padding: 0.4em 0;
font-size: 0.8em;
font-weight: bold;
}
.profile-action {
float: right;
background-color: #eee;
padding: 0.4em;
border-radius: 2px;
color: inherit;
text-decoration: none;
font-size: 0.8em;
font-weight: bold;
}
.p-tooltip .profile-nnm {
margin: -40px auto 0;
width: 80px;
height: 80px;
background-size: 80px;
border: 3px solid #F0F0F0;
border-radius: 5px;
}
.profile-info {
text-align: center;
padding: 10px;
opacity: 0;
}
.profile-title {
font-size: 1.6em;
margin: 0;
}
.profile-description {
margin: 0;
font-size: 0.8em;
}
.profile-items {
margin: 0px;
padding: 10px;
}
.profile-items:after {
content:'';
display: table;
clear: both;
}
.profile-items li {
width: 80px;
height: 80px;
background-size: cover;
background-position: center;
float: left;
display: block;
border-radius: 3px;
}
.profile-items li:not(:first-child) {
margin-left: 10px;
}
.profile-items li:nth-child(1) {
background-image: url(https://o.twimg.com/1/proxy.jpg?t=FQQVBBgwaHR0cHM6Ly9pLnl0aW1nLmNvbS92aS9CM3lna2lYRXVyWS9ocWRlZmF1bHQuanBnFAIWABIA&s=z1wybbbNHF0pyLthl3xhxVBNjbYlAEWEzPd-dUtrWOY);
}
.profile-items li:nth-child(2) {
background-image: url(https://pbs.twimg.com/media/B7pkXfgCIAAwoY0.jpg:thumb);
}
.profile-items li:nth-child(3) {
background-image: url(https://pbs.twimg.com/media/B7A3NHjIIAIt6eg.png:large);
}
.profile-header {
-webkit-transform: translate(0, -50px);
-moz-transform: translate(0, -50px);
transform: translate(0, -50px);
-webkit-transition: all 0.2s ease-out;
-moz-transition: all 0.2s ease-out;
transition: all 0.2s ease-out;
-webkit-transition-delay: 0.1s;
-moz-transition-delay: 0.1s;
transition-delay: 0.1s;
opacity: 0;
}
.profile-info {
-webkit-transform: translate(0, 50px);
-moz-transform: translate(0, 50px);
transform: translate(0, 50px);
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
-webkit-transition-delay: 0.1s;
-moz-transition-delay: 0.1s;
transition-delay: 0.1s;
}
.p-tooltip .profile-ava {
-webkit-transform: scale(0.5) translate(0, -10px);
-moz-transform: scale(0.5) translate(0, -10px);
transform: scale(0.5) translate(0, -10px);
-webkit-transition: all 0.5s ease-out;
-moz-transition: all 0.5s ease-out;
transition: all 0.5s ease-out;
-webkit-transition-delay: 0.1s;
-moz-transition-delay: 0.1s;
transition-delay: 0.1s;
opacity: 0;
}
.profile-items li {
-webkit-transform: translate(0, 50px);
-moz-transform: translate(0, 50px);
transform: translate(0, 50px);
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
-webkit-transition-delay: 0.3s;
-moz-transition-delay: 0.3s;
transition-delay: 0.3s;
opacity: 0;
}
.profile-items li:nth-child(2) {
-webkit-transition-delay: 0.35s;
-moz-transition-delay: 0.35s;
transition-delay: 0.35s;
}
.profile-items li:nth-child(3) {
-webkit-transition-delay: 0.4s;
-moz-transition-delay: 0.4s;
transition-delay: 0.4s;
}
.k-isim:hover .p-tooltip {
visibility: visible;
opacity: 1;
max-height: 600px;
}
.k-isim:hover .profile-header, .k-isim:hover .profile-info, .k-isim:hover .p-tooltip .profile-ava, .k-isim:hover .profile-items li {
-webkit-transform: translate(0, 0) scale(1);
-moz-transform: translate(0, 0) scale(1);
transform: translate(0, 0) scale(1);
opacity: 1;
}
我沒有驗證您所有的CSS,但與正常運行的演示相比,您做了一些更改,這使您的演示無法正常工作。 我認為問題是當您的文本(鏈接或按鈕)與其容器之間沒有邊距(或填充)時,因為如果您嘗試將鼠標懸停在右側,則動畫對兩個文本都有效,但是從左,頂部或底部懸停時,我認為在懸停容器和文本之間需要一些時間。 我添加了邊框以查看我在說什么:
因此,為避免此問題,您必須考慮所有這些。 例如,您可以像我在這里所做的那樣, 在您的kisi-isim
類中添加一些填充。
當然,我試圖向您展示我認為問題的根源以及如何避免它。 您必須編輯代碼才能以自己喜歡的方式獲得所需的結果。
希望能對您有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.