只改变背景图的横向位置(或者纵向位置).javascript怎么写
两个同时改又怎么写
------解决方案--------------------
- HTML code
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> div { margin:0 auto; width:800px; /*1320*/ height:513px; background:url(http://whoisleon.com/wp-content/themes/whoisleon/images/n_cloud1.jpg) repeat; } </style> </head> <body> <div id="test"></div> <script> var $ = function(id){ return document.getElementById(id); }; var obj = $('test'); var i = 0; setInterval(function(){ obj.style.backgroundPosition = '0 '+(--i)+'px'; }, 30) </script> </body> </html>
------解决方案--------------------
Object.style.backgroundPositionX=position //横向
Object.style.backgroundPositionY=position //竖向