我有絕對位置3個按鈕:如何根據鼠標移動/位置應用效果?
.micro {
position:absolute;
}
#micro_1 {
left:1165px;
top:176px;
}
#micro_2 {
left:800px;
top:300px;
}
#micro_3 {
left:300px;
top:400px;
}
我想褪色這些3個元素,當鼠標移動和更靠近所述圖像中的一個。 如果鼠標靠近圖像1,圖像1漸漸消失。圖像2和圖像3漸漸消失。 依此類推。
我可以使用jQuery知道鼠標的位置:
$('body').mousemove(function(e){
$('#mouse_position').html("mouse position: x=" + e.pageX + "; y=" + e.pageY);
所以我想我可以做一些數學應用的效果。
我做了什麼:
$('body').mousemove(function(e){
$('#mouse_position').html("mouse position: x=" + e.pageX + "; y=" + e.pageY);
if (e.pageX > 394 && e.pageX < 533) {
$('#lueur_video_1').fadeIn('slow');
$('#lueur_video_2').fadeOut('slow');
$('#lueur_video_3').fadeOut('slow');
}
if (e.pageX > 533 && e.pageX < 722) {
$('#lueur_video_2').fadeIn('slow');
$('#lueur_video_1').fadeOut('slow');
$('#lueur_video_3').fadeOut('slow');
}
if (e.pageX > 722 && e.pageX < 1116) {
$('#lueur_video_3').fadeIn('slow');
$('#lueur_video_1').fadeOut('slow');
$('#lueur_video_2').fadeOut('slow');
}
你可以創建一個到目前爲止在jsfiddle.net上的工作版本嗎? –
@Explosion Pills看到這個小提琴:http://jsfiddle.net/Vinyl/2khgw/1/這是非常基本的。 –