// 获取工程案例的包裹 var objectlist = document.getelementsbyclassname("banner_object_list")[0]; // 获取工程案例中图片的列表 var objectitems = objectlist.getelementsbytagname("li"); // 获取工程案例的切换按钮 var objectbuttonleft = document.getelementsbyclassname("object_button_pre")[0]; var objectbuttonright = document.getelementsbyclassname("object_button_next")[0]; // 克隆工程案例列表的第一个元素、第二个元素放在列表的最后一位; var objectfirstclone = objectitems[0].clonenode(true); var objectsecondclone = objectitems[1].clonenode(true); var objectlastclone = objectitems[objectitems.length - 1].clonenode(true); var objectlasttwoclone = objectitems[objectitems.length - 2].clonenode(true); objectlist.appendchild(objectfirstclone); objectlist.appendchild(objectsecondclone); objectlist.insertbefore(objectlastclone, objectitems[0]); objectlist.insertbefore(objectlasttwoclone, objectitems[0]); // 根据新闻的数量来决定包裹的宽度width; var objectitemswidth = (objectitems[0].offsetwidth + 30); objectlist.style.width = objectitemswidth * (objectitems.length) + "px"; var objectindex = 2; objectlist.style.transform = "translatex(" + (-objectitemswidth * objectindex) + "px)"; function objectauto() { objectindex++; if (objectindex >= objectitems.length - 2) { objectlist.style.transitionduration = "0s"; objectlist.style.transform = "translatex(" + (-objectitemswidth * 1) + "px)"; objectindex = 2; objectlist.offsetleft; } objectlist.style.transitionduration = "0.81s"; objectlist.style.transform = "translatex(" + (-objectitemswidth * objectindex) + "px)"; } function objectgopre() { objectindex--; if (objectindex < 0) { objectlist.style.transitionduration = "0s"; objectlist.style.transform = "translatex(" + (-objectitemswidth * (objectitems.length - 4)) + "px)"; objectindex = objectitems.length - 5; objectlist.offsetleft; } objectlist.style.transitionduration = "0.81s"; objectlist.style.transform = "translatex(" + (-objectitemswidth * objectindex) + "px)"; } var objecttimer = setinterval(objectauto, 3600); objectbuttonleft.addeventlistener("click", function() { clearobjecttimer = clearinterval(objecttimer); objectgopre(); objecttimer = setinterval(objectauto, 3600); }) objectbuttonright.addeventlistener("click", function() { clearobjecttimer = clearinterval(objecttimer); objectauto(); objecttimer = setinterval(objectauto, 3600); }) // function getstyle(obj, attr) { // if (obj.currentstyle) { // return obj.currentstyle[attr]; // } else { // return document.defaultview.getcomputedstyle(obj, null)[attr]; // } // } // function getmarginleft(obj, index) { // var arr = getstyle(obj[0], "margin").split(" ") // return marginleft = parsefloat(arr[index]) // }