<a href="JavaScript:jQuery('.mylightbox').html5lightbox();" style="user-select: auto;">點擊初始化對應鏈接的html5lightbox()</a>
如何把這個寫成jQuery的mouseover函式和mouseout函式,不需要點擊,而是通過滑鼠是否懸停來自動觸發對應的html5lightbox()的開和關呢?
<script type="text/javascript">
$(document).ready(function(){
$("a").mouseover(function(){
.......
});
$("a").mouseout(function(){
.........
});
</script>
uj5u.com熱心網友回復:
參考一下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<a href="javascript:;" class="user-select-auto">點擊初始化對應鏈接的html5lightbox()</a>
<a href="javascript:;" class="user-select">html5lightbox()</a>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
jQuery(function($){
$('a.user-select-auto').hover(function () {
$(this).css({"background-color":"red"});
},
function () {
$(this).css({"background-color":"blue"});
}
);
$( "a.user-select" ).mouseover(function() {
$( this ).css({"color":"red"});
}).mouseout(function() {
$( this ).css( "color","black" );
});
});
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/148195.html
標籤:JavaScript
