我用tippy.js创建了多个工具提示内容但我不能制作动态内容。它仅显示第一个工具提示模板。
第二个问题是,当我放入style: display:none
工具提示包装器时,工具提示不显示。当我删除style: display:none
时,工具提示内容显示正常(必须隐藏)。
如何使用子模板制作工具提示?
这里还有 codepen 示例:https ://codepen.io/wpuzman/pen/mQeeRQ
$(document).ready(function() {
$('.box').each(function(){
tippy(this, {
arrow: true,
arrowType: 'round',
size: 'large',
duration: 500,
animation: 'scale',
placement: 'left',
interactive: true,
theme: 'google',
content: document.querySelector('.tooltip_templates').cloneNode(true)
});
});
});
.wrap {
margin: 150px;
position: relative;
}
.box {
float: left;
margin-right: 10px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/tippy.js@3/dist/tippy.all.min.js"></script>
<div class="wrap">
<div class="box">
<img src="https://picsum.photos/50/50" alt="">
<div class="tooltip_templates" style="display: none;">
<div class="tooltip-content">
<img src="https://picsum.photos/150/150" alt="">
<h3>Test image 1</h3>
</div>
</div>
</div>
<div class="box">
<img src="https://picsum.photos/50/50" alt="">
<div class="tooltip_templates" style="display: none;">
<div class="tooltip-content">
<img src="https://picsum.photos/150/150" alt="">
<h3>Test image 2</h3>
</div>
</div>
</div>
<div class="box">
<img src="https://picsum.photos/50/50" alt="">
<div class="tooltip_templates" style="display: none;">
<div class="tooltip-content">
<img src="https://picsum.photos/150/150" alt="">
<h3>Test image 3</h3>
</div>
</div>
</div>
<div class="box">
<img src="https://picsum.photos/50/50" alt="">
<div class="tooltip_templates" style="display: none;">
<div class="tooltip-content">
<img src="https://picsum.photos/150/150" alt="">
<h3>Test image 4</h3>
</div>
</div>
</div>
<div class="box">
<img src="https://picsum.photos/50/50" alt="">
<div class="tooltip_templates" style="display: none;">
<div class="tooltip-content">
<img src="https://picsum.photos/150/150" alt="">
<h3>Test image 5</h3>
</div>
</div>
</div>
<div class="box">
<img src="https://picsum.photos/50/50" alt="">
<div class="tooltip_templates" style="display: none;">
<div class="tooltip-content">
<img src="https://picsum.photos/150/150" alt="">
<h3>Test image 6</h3>
</div>
</div>
</div>
</div>