📄 tack.js
字号:
// preload the swap image
var preload = new Image();
preload.src = "sail_l.gif";
// set the initial direction to right
var go_right = true;
// a function to move a <div> across the page
function set_sail()
{
// get the div object
var obj = document.getElementById("boat");
// get the window width
var ext = document.body.clientWidth;
// if direction is right
if(go_right )
// move right by 1 pixel
obj.style.left = (parseInt(obj.style.left)+1)+"px";
else
// otherwise move left by 1 pixel
obj.style.left = (parseInt(obj.style.left)-1)+"px";
// when the layer's left edge is 15 pixels beyond the window's right edge
if(parseInt(obj.style.left ) >= ( ext + 15 ) )
{
// change the direction to left
go_right=false;
// swap the image to a left-facing version
document.getElementById("boat_image").src = "sail_l.gif";
}
// when the layer's left edge is 75 pixels beyond the window's left edge
if(parseInt(obj.style.left) <= -75)
{
// change the direction to right
go_right = true;
// swap the image to a right-facing version
document.getElementById("boat_image").src = "sail_r.gif";
}
// set the interval to call this function
window.setTimeout("set_sail()", 50);
}
// start the routine
set_sail();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -