贴码
<script>
//容器寬高
var banner_x=$('.index-two').width()-320;
var banner_y=$('.index-two').height()-280;
var time;
var type_l;
//計時器
function reload(){
var left=parseInt($('.index-two-title').find('img').css('left').replace("px",""));
var top=parseInt($('.index-two-title').find('img').css('top').replace("px",""));
var type;
function check_type(){
type=Math.round(Math.random()*2 + 2);
if(type==type_l){
check_type();
}
}
check_type();
if(type==1){
var x= 0;
var y=0;
}else if(type==2){
var x=0;
// var y=banner_y;
var y=Math.round(Math.random()*banner_y);
}else if(type==3){
var x=Math.round(Math.random()*banner_x);
var y=0;
}else{
var x=banner_x;
var y=banner_y;
}
type_l=type;
var size_x=(x-left)/100;
var size_y=(y-top)/100;
var x_max=0;
var y_max=0;
time=setInterval(function(){
x_max+=size_x;
y_max+=size_y;
// console.info(y_max);
console.info(Math.round(x_max));
console.info(x-left);
console.info('-------');
$('.index-two-title').find('img').css({'left':parseInt(left)+parseInt(x_max)+'px','top':parseInt(top)+parseInt(y_max)+'px'});
if(Math.round(x_max) ==(x-left) && Math.round(y_max) ==(y-top)){
clearInterval(time);
reload();
}
},10)
}
reload();
$('.index-two-title').find('img').eq(0).mouseenter(function(){
clearInterval(time);
})
$('.index-two-title').find('img').eq(0).mouseleave(function(){
reload();
})
</script>
预览效果
http://static.prient.top/zhaoming/