我需要将元素的移动从左移到500像素,而不是在给定的js下旋转。 提前谢谢。
var leftItem = document.getElementById('item0'),
rightItem = document.getElementById('item1');
;(function(){
var throttle = function(type, name, obj){
var obj = obj || window;
var running = false;
var func = function(){
if (running){ return; }
running = true;
requestAnimationFrame(function(){
obj.dispatchEvent(new CustomEvent(name));
running = false;
});
};
obj.addEventListener(type, func);
};
throttle("scroll", "optimizedScroll");
})();
window.addEventListener("optimizedScroll", function(){
leftItem.style.transform = "rotate(-" + window.pageYOffset + "deg)";
rightItem.style.transform = "rotate(" + window.pageYOffset + "deg)";
})
答案 0 :(得分:0)
您可以使用translateX():
leftItem.style.transform = "translateX(500px)";
当然,这取决于你想要触发它。