使用JS實現在圖片上顯示左右箭頭的翻頁代碼,預覽效果網址:http:///keleyi/phtml/picnext/
本實例使用了javascript的onmousemove 事件。onmousemove 事件會在鼠標指針移動時發生。
語法
onmousemove="SomeJavaScriptCode"
SomeJavaScriptCode是必需參數。規定該事件發生時執行的 JavaScript。
下面是核心代碼(完整代碼請在效果頁面查看源代碼):
<script type="text/javascript">
function KeleyiImgNext(bigimg) {
var lefturl = "01.html";
var righturl ="03.html";
var imgurl = righturl;
var width = bigimg.width;
var height = bigimg.height;
bigimg.onmousedown = bigimg.onmousemove = function () {
if (event.offsetX < width / 2) {
imgurl = lefturl;
if (imgurl != "#")
bigimg.style.cursor = 'url(images/arr_left.cur),auto';
else
bigimg.style.cursor = 'default';
} else {
imgurl = righturl;
if (imgurl != '#')
bigimg.style.cursor = 'url(images/arr_right.cur),auto';
else
bigimg.style.cursor = 'default';
}
}
bigimg.onmouseup = function () {
if (imgurl != '#')
top.location = imgurl;
}
}
</script>
<img onmouseover="KeleyiImgNext(this)" src="http:///keleyi/phtml/picnext/images/k02.jpg" alt="keleyi" />