在你原来的代码上进行了修改,加粗倾斜的部分是添加或者修改的位置
<script>
var timer1 = null
var el = null
var left = 1
function moveItRight() {
if (parseInt(el.style.left) >(screen.width - 50)) //el.style.left = 0
{
left = -1
}
else if (parseInt(el.style.left) <= 0) {
left = 1
}
el.style.left = parseInt(el.style.left) + 2 * left + 'px'//本题目最关键的一句代码,让el对象的左边距每次循环都增加2像素,也就是向右移动了2像素
timer1 = setTimeout(moveItRight, 25)//隔25毫秒后运行一次moveItRight函数
}
window.onload = function () {
el = document.getElementById("div1")
el.style.left = '500px'
moveItRight()
}
</script>
var datas = [{imgSrc:"(图片 )"},
{imgSrc:"(图片 )"},
{imgSrc:"(图片 )"},
{imgSrc:"(图片 )"},
{imgSrc:"(图片 )"},
{imgSrc:"(图片 )"}
]
var banner = document.getElementById("banner")
var list = document.getElementById("list")
for(var i = 0,len = datas.lengthi<leni++){
var div = document.createElement("div")
var li = document.createElement("li")
if(i==0){ //默认第一项轮播项显示 对应的控制按钮被选中
div.className = "item active"
li.className = "active"
}else{ //其他项隐藏 其他的控制按钮样式不改变
div.className = "item"
li.className = ""
}
div.innerHTML = '<a href="' + datas[i].targetSrc + '">' +
'<img src="' + datas[i].imgSrc + '" />' +
'</a>'
li.innerHTML = i + 1
banner.appendChild(div)
list.appendChild(li)
}
var lunBo = document.getElementById("lunBo")
var items = document.querySelectorAll("#lunBo #banner .item")
var lis = document.querySelectorAll("#lunBo #list li")
var currentIndex = 0//(控制按钮和轮播项共同的索引)
for(var i = 0,len = lis.lengthi<leni++){
lis[i].index = i
lis[i].onmouseenter = function(){
currentIndex = this.index
for(var j = 0j<lenj++){
lis[j].className = ""
items[j].className = "item"
}
this.className = "active"
items[this.index].className = "item active"
}
}
var termId //全局变量
function autoPlay(){
termId = setInterval(function(){
currentIndex++
if(currentIndex==lis.length){
currentIndex = 0
}
lis[currentIndex].onmouseenter()
},3000)
}
autoPlay()//打开页面自动轮播
//鼠标进入停止轮播
lunBo.onmouseenter = function(){
clearInterval(termId)
}
//鼠标离开继续轮播
lunBo.onmouseleave = function(){
autoPlay()
}
我这还有其他的,先采纳一下加我,我给你发