1 回答

TA貢獻1817條經驗 獲得超6個贊
不要設置srciframe 的 。僅當用戶第一次懸停時設置它。
在下面的代碼片段中,您可以看到 iframe 內的頁面最初并未加載,直到您將鼠標懸停在眼睛上。
我特意發表了評論display: none;,以便您可以觀察到該頁面未加載。
$(".text").mouseover(function() {
var src = $(this).children(".test").attr('src');
if(!src){
src = $(this).children(".test").attr('data-src');
$(this).children(".test").attr('src', src);
}
$(this).children(".test").show();
}).mouseout(function() {
$(this).children(".test").hide();
});
.text {
color: #069;
cursor: pointer;
text-decoration: none;
}
.test {
//display: none;
position: absolute;
border: 1px solid #000;
width: 400px;
height: 400px;
}
<span style="font-size:120%;"><b><a class="text"> 👁
<iframe class="test" data-src="https://www.google.de/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"></iframe>
</a></b></span>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報