I have a script with loops to generate thumbnails images. I add a div hidden hover each thumbnail to show associate caption. But i'm not able to to show caption when mouse over the image..
我有一个带循环的脚本来生成缩略图图像。我添加一个div隐藏悬停每个缩略图以显示关联标题。但是当鼠标悬停在图像上时,我无法显示标题..
Here is my jsfiddle to understand it: https://jsfiddle.net/mytom/zgytmyt0/
这是我理解它的jsfiddle:https://jsfiddle.net/mytom/zgytmyt0/
-> I want to show caption when on mouseover the image et hide caption when on mouseout.
- >我希望在鼠标悬停时显示标题,并在鼠标输出时隐藏标题。
CSS CODE:
CSS代码:
#componentWrapper .thumbHolder {
position:absolute;
width:100%;
height:107px;
left:0px;
bottom:0px;
background:#222;
overflow:hidden;
display:block;
}
#componentWrapper .thumbContainer {
position:absolute;
height:67px;
top:40px;
/*left, width set in jquery*/
}
#componentWrapper .thumbInnerContainer {
position:absolute;
height:67px;
/*width set in jquery*/
top:0px;
left:0px;
}
#componentWrapper .thumbs {
position:relative;
top:0px;
left:0px;
margin-right: 2px !important;
width:100px;
height:67px;
float:left;
background:#111;
}
#componentWrapper .thumb_img {
position:relative;
display:block;
top:0px;
left:0px;
width:100%;
height:100%;
opacity: .3;
-webkit-transition: opacity 0.5s ease-out;
-moz-transition: opacity 0.5s ease-out;
-ms-transition: opacity 0.5s ease-out;
-o-transition: opacity 0.5s ease-out;
transition: opacity 0.5s ease-out;
}
#componentWrapper .thumb_img:hover {
opacity: 1;
-webkit-transition: opacity 0.3s ease-out;
-moz-transition: opacity 0.3s ease-out;
-ms-transition: opacity 0.3s ease-out;
-o-transition: opacity 0.3s ease-out;
transition: opacity 0.3s ease-out;
}
/* thumb caption */
#componentWrapper .thumbCaptionHolder {
background-color: rgba(0, 0, 0, 0.6);
height: 67px;
left: 0;
/*overflow: hidden;*/
padding: 3px;
position: absolute;
top: 0px;
width: 95px;
}
#componentWrapper .thumbCaption {
color: #e5e5e5;
font-family: sans-serif;
font-size: 10px;
cursor:default;
}
HTML CODE:
HTML代码:
<div id="componentWrapper">
<div class="thumbHolder">
<div class="thumbContainer" style="width: 1266px; left: 50px;">
<div class="thumbInnerContainer" style="top: 0px; left: 0px; width: 8568px;">
</div>
</div>
</div>
</div>
JS SCRIPT:
JS脚本:
var thumbInnerContainer = $('.thumbInnerContainer');
var _item = [
{id: 'GASFa7rkLtM', type: 'video', title: 'description1',
thumb: 'https://i.ytimg.com/vi/GASFa7rkLtM/mqdefault.jpg'},
{id: 'R5txNOdumzQ', type: 'video', title: 'description2', thumb:
'https://i.ytimg.com/vi/R5txNOdumzQ/mqdefault.jpg'},
{id: 'PELlHslllk0', type: 'video', title: 'description3', thumb:
'https://i.ytimg.com/vi/PELlHslllk0/mqdefault.jpg'}
];
var len = _item.length,i = 0,thumb, div, _item;
for (i; i < len; i++) {
div = $('<div/>').addClass('thumbs').attr({
'data-id': i + 1,
'data-type': _item[i].type
});
div.attr('path', _item[i].id);
div.appendTo(thumbInnerContainer);
//create thumb
thumb = $(new Image()).addClass('thumb_img').appendTo(div).attr('alt', _item[i].title).css({
cursor: 'default'
}).error(function (e) {
//console.log("thumb error " + e);
}).attr('src', _item[i].thumb);
// thumb title
var thumbCaption = $('<div><p class="thumbCaption"><span>' + _item[i].title + '</span></p></div>').addClass('thumbCaptionHolder').attr('id', _item[i].id).appendTo(div).css({
top: '0px',
display: 'none'
})
// how to show thumbCaptionHolder div when mouseover the img????
} //end of loop
thank you!
谢谢!
1 个解决方案
#1
1
Okay, the solution is easy.
好的,解决方案很简单。
#componentWrapper .thumbs:hover > .thumbCaptionHolder{
display:block !important;
}
you will need that !important
or it won't work.
你将需要它!重要的或它将无法工作。
You also have a small mistake in the jquery code.
你在jquery代码中也有一个小错误。
change:
更改:
var thumbCaption = $('<div><p class="thumbCaption"><span>' + _item[i].title + '</span></p></div>').addClass('thumbCaptionHolder').attr('id', _item[i].id).appendTo(div).css({
top: '0px',
display: 'none'
})
to:
至:
var thumbCaption = $('<div><p class="thumbCaption"><span>'+_item[i].title+'</span></p></div>').addClass('thumbCaptionHolder').attr('id',_item[i].id).appendTo(div).css({
'top': '0px',
'display': 'none'
})
and here you find why you need to change.
在这里你找到了你需要改变的原因。
And a working Demo
还有一个有效的演示
#1
1
Okay, the solution is easy.
好的,解决方案很简单。
#componentWrapper .thumbs:hover > .thumbCaptionHolder{
display:block !important;
}
you will need that !important
or it won't work.
你将需要它!重要的或它将无法工作。
You also have a small mistake in the jquery code.
你在jquery代码中也有一个小错误。
change:
更改:
var thumbCaption = $('<div><p class="thumbCaption"><span>' + _item[i].title + '</span></p></div>').addClass('thumbCaptionHolder').attr('id', _item[i].id).appendTo(div).css({
top: '0px',
display: 'none'
})
to:
至:
var thumbCaption = $('<div><p class="thumbCaption"><span>'+_item[i].title+'</span></p></div>').addClass('thumbCaptionHolder').attr('id',_item[i].id).appendTo(div).css({
'top': '0px',
'display': 'none'
})
and here you find why you need to change.
在这里你找到了你需要改变的原因。
And a working Demo
还有一个有效的演示