代码有bug,修改后如下:
需要注意,拷贝下面这段代码,保存为 html后缀名的文件;需要自己在相同的目录下,放置两张图片,小图片.jpg 大图片.jpg
效果如下图:当鼠标悬停在小图片上面的时候,会显示大图片;鼠标移出,隐藏大图片。
问题:定位需要读者自己去实现一下吧,偷懒了。感谢楼上分享!
<!doctype html><html>
<head>
<meta charset=utf-8>
</head>
<body>
你要显示特效的html
<img src="小图片.jpg" width="200px" height="200px" id="littleimg" onmouseout="hoverHiddendiv()" onmouseenter="hoverShowDiv()" />
<div style="width:200pxheight:80pxborder:1px solide #aaccffdisplay:none" id="divHover" >
大图片显示如下
<img src="大图片.jpg" width="500px" height="300px" id="bigimg" />
</div>
<script type="text/javascript">
let divHover = document.getElementById("divHover")
function hoverShowDiv() {
console.log("显示大图片")
divHover.style.display = "block"
divHover.style.top = document.getElementById("littleimg").style.top + 10
divHover.style.left = document.getElementById("littleimg").style.left + 10
}
function hoverHiddendiv() {
console.log("显示小图片")
divHover.style.display = "none"
}
</script>
</body>
</html>
实现鼠标悬停显示文字,html中使用title属性就可实现显示文字的效果,这个属性还是比较实用的,你可以参考下<a href="#" title="这里是显示的文字">hello</a>
当鼠标悬停在 hello上一会就会有文字 "这里是显示的文字" 显示。
鼠标上变化的文字脚本说明:
把如下代码加入<body>区域中
<SCRIPT language="JavaScript1.2">
<!--
var scroller_msg='Hi,网络编程站欢迎你的光临!'
var dismissafter=0
var initialvisible=0
if (document.all)
document.write('<marquee id="curscroll" style="position:absolutewidth:150pxborder:1px solid blackfont-size:14pxbackground-color:whitevisibility:hidden">'+scroller_msg+'</marquee>')
function followcursor(){
//move cursor function for IE
if (initialvisible==0){
curscroll.style.visibility="visible"
initialvisible=1
}
curscroll.style.left=document.body.scrollLeft+event.clientX+10
curscroll.style.top=document.body.scrollTop+event.clientY+10
}
function dismissmessage(){
curscroll.style.visibility="hidden"
}
if (document.all){
document.onmousemove=followcursor
document.ondblclick=dismissmessage
if (dismissafter!=0)
setTimeout("dismissmessage()",dismissafter*1000)
}
//-->
</SCRIPT>
================================
鼠标箭头效果
脚本说明:
把如下代码加入<body>区域中
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var x, y, xold, yold, xdiff, ydiff
var dir = Array()
dir[0] = "n-resize"
dir[1]="ne-resize"
dir[2]="e-resize"
dir[3]="se-resize"
dir[4] = "s-resize"
dir[5]="sw-resize"
dir[6]="w-resize"
dir[7]="nw-resize"
document.onmousemove = FindXY
function display(direction) {
document.body.style.cursor = dir[direction]
}
function FindXY(loc) {
x = (document.layers) ? loc.pageX : event.clientX
y = (document.layers) ? loc.pageY : event.clientY
xdiff = x - xold
ydiff = y - yold
if ((xdiff < 2) &&(ydiff <-2)) display(0)
if ((xdiff < 2) &&(ydiff > 2)) display(4)
if ((xdiff > 2) &&(ydiff < 2)) display(2)
if ((xdiff <-2) &&(ydiff < 2)) display(6)
if ((xdiff > 2) &&(ydiff > 2)) display(3)
if ((xdiff > 2) &&(ydiff <-2)) display(1)
if ((xdiff <-2) &&(ydiff > 2)) display(5)
if ((xdiff <-2) &&(ydiff <-2)) display(7)
xold = x
yold = y
}
// End -->
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)