【发布时间】:2014-02-04 15:58:45
【问题描述】:
我正在尝试让 Magnific Popup 为我工作,但我遇到了困难。当谈到 Javascript 和 Jquery 时,我有点新手。我已经浏览了几天的文档(字面意思)并搜索stackoverflow。我已经找到了一些答案,但它似乎不适合我想要的。
我想要做的是通过缩略图在多个 div 中显示一个画廊,这些 div 有一些样式。最好我希望隐藏长描述,直到通过单击各个画廊项目打开画廊。然后在 mfp-imag 的右侧(向右浮动)显示长描述(我将向左浮动)。
HTML
<div class="fourColumns">
<div class="fourColumnsHeader">
Image Title<br>
<a class="with_caption" title="This is the Caption" href="/images/image.jpg"><img src="/images/image.jpg" alt="Image" width="223" height="131"></a>
<div>
This is one long discription<br>
This is some more detail...<br><br>
- Bullet<br> <!-- This is just a placeholder for an ul -->
- Bullet<br>
- Bullet
</div>
</div>
</div>
<div class="fourColumns">
...
</div>
<div class="fourColumns">
...
</div>
<div class="fourColumns">
...
</div>
我想我需要这样的东西 Javascript
<script type="text/javascript">
$('.fourColumns').magnificPopup({
delegate: 'a', // child items selector, by clicking on it popup will open
type: 'image',
// other options
gallery: {enabled: true},
image: {
markup: '<div class="mfp-figure">'+
'<div class="mfp-close"></div>'+
'<div class="mfp-img"></div>'+
'<div class="mfp-description"></div>'+
'<div class="mfp-bottom-bar">'+
'<div class="mfp-title"></div>'+
'<div class="mfp-counter"></div>'+
'</div>'+
'</div>', // Popup HTML markup. `.mfp-img` div will be replaced with img tag, `.mfp-close` by close button
cursor: 'mfp-zoom-out-cur', // Class that adds zoom cursor, will be added to body. Set to null to disable zoom out cursor.
tError: '<a href="%url%">The image</a> could not be loaded.' // Error message
},
preloader: true,
callbacks: {
elementParse: function(item) {
// Function will fire for each target element
// "item.el" is a target DOM element (if present)
// "item.src" is a source that you may modify
// store the text in imgCaption variable, - if you will need this later on
var imgCaption = item.el.find('p'); // This is wrong.
// append the text to the element
item.content.find('.mfp-description').html(imgCaption); // This is wrong.
},
}
});
</script>
我希望这足够彻底。任何帮助将不胜感激。谢谢! :)
【问题讨论】:
标签: jquery magnific-popup