บทความนี้อธิบายถึงวิธีการสั่นสะเทือนเอฟเฟกต์พิเศษของการปัดเมาส์ JS เหนือภาพ แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = gb2312">>
<title> ปัดเมาส์ผ่านเอฟเฟกต์การสั่นสะเทือนของรูปภาพ </title>
<style> .shakeimage {
ตำแหน่ง: ญาติ
-
</style>
</head>
<body>
<ภาษาสคริปต์ = JavaScript1.2>
-
Var Reflector = 3
var stopit = 0
var a = 1
ฟังก์ชั่น init (ซึ่ง) {
StopIt = 0
เขย่า = ไหน
Shake.style.left = 0
Shake.style.top = 0
-
ฟังก์ชั่น rattleimage () {
if ((! document.all &&! document.getElementById) || stopit == 1)
กลับ
ถ้า (a == 1) {
shake.style.top = parseint (shake.style.top)+อธิการบดี
-
อื่นถ้า (a == 2) {
Shake.style.left = ParseInt (shake.style.left)+อธิการบดี
-
อื่นถ้า (a == 3) {
shake.style.top = parseint (shake.style.top) -rector
-
อื่น{
Shake.style.left = ParseInt (shake.style.left) -rector
-
ถ้า (a <4)
A ++
อื่น
a = 1
settimeout ("rattleimage ()", 50)
-
ฟังก์ชั่น stopRattle (ซึ่ง) {
Stopit = 1
her.style.left = 0
her.style.top = 0
-
-
</script>
<img onMouseOver = "init (this); rattleimage ()" onMouseOut = "stopRattle (นี่)" src = "/images/csrcode.ico" style = "เคอร์เซอร์: ตัวชี้;"/>
<img onMouseOver = "init (this); rattleimage ()" onMouseOut = "stopRattle (นี่)" src = "/images/changshi.ico" style = "เคอร์เซอร์: ตัวชี้;"/>
<img onMouseOver = "init (this); rattleimage ()" onMouseOut = "stopRattle (นี่)" src = "/images/links.ico" style = "เคอร์เซอร์: pointer;"/>
เลื่อนเมาส์ผ่านเอฟเฟกต์ตัวอย่างภาพ
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน