tobee
Erfahrenes Mitglied
Ich wollte mal nachfragen ob jemanden von euch Optimierungen einfällt bzw. findet die die Performance ein wenig verbessern.
VIelen Dank
VIelen Dank
Javascript:
var boolMouseDown = false;
var objMouse, objSelectionStart = [0,0];
var objSettings = {
id: "selection",
unit: "px"
};
var objIcons = [
{ id: "qwe", x: 100, y: 100, type: "folder", seleted: false },
{ id: "asd", x: 200, y: 200, type: "folder", seleted: false },
{ id: "yxc", x: 300, y: 300, type: "folder", seleted: false },
{ id: "wer", x: 400, y: 400, type: "folder", seleted: false }
];
window.onload = function() {
var objSelection = document.createElement("div");
objSelection.id = objSettings.id;
objSelection.style.position = "absolute";
objSelection.style.display = "none";
document.body.appendChild(objSelection);
for(var intCount = 0; intCount < objIcons.length; intCount++){
var objIcon = document.createElement("img");
objIcon.id = objIcons[intCount].id;
objIcon.style.position = "absolute";
objIcon.style.top = objIcons[intCount].y + objSettings.unit;
objIcon.style.left = objIcons[intCount].x + objSettings.unit;
objIcon.src = "misc/images/icon.png";
objIcon.width = "96";
objIcon.height = "96";
document.body.appendChild(objIcon);
}
}
window.onclick = function() {
for(var intCount = 0; intCount < objIcons.length; intCount++){
document.getElementById(objIcons[intCount].id).style.border = "";
document.getElementById(objIcons[intCount].id).style.margin = "";
}
}
window.onmousedown = window.onmousemove = function(objEvent){
objMousePosition = [objEvent.clientX, objEvent.clientY];
if(objEvent.type == "mousedown") {
boolMouseDown = true;
var objSelection = document.getElementById(objSettings.id);
objSelection.style.top = objEvent.clientY + objSettings.unit;
objSelection.style.left = objEvent.clientX + objSettings.unit;
objSelection.style.width = ( objEvent.clientX - parseInt(objSelection.style.left) ) + objSettings.unit;
objSelection.style.height = ( objEvent.clientY - parseInt(objSelection.style.top) ) + objSettings.unit;
objSelection.style.display = "block";
objSelectionStart = [objEvent.clientX, objEvent.clientY];
}
else if(objEvent.type == "mousemove") {
if(boolMouseDown){
var objSelection = document.getElementById(objSettings.id);
if(objEvent.clientX < objSelectionStart[0]) {
document.getElementById("selection").style.left = objEvent.clientX + objSettings.unit;
objSelection.style.width = ( objSelectionStart[0] - parseInt(objSelection.style.left) ) + objSettings.unit;
}
else {
objSelection.style.width = ( objEvent.clientX - parseInt(objSelection.style.left) ) + objSettings.unit;
}
if(objEvent.clientY < objSelectionStart[1]) {
document.getElementById("selection").style.top = objEvent.clientY + objSettings.unit;
objSelection.style.height = ( objSelectionStart[1] - parseInt(objSelection.style.top) ) + objSettings.unit;
}
else {
objSelection.style.height = ( objEvent.clientY - parseInt(objSelection.style.top) ) + objSettings.unit;
}
for(var intCount = 0; intCount < objIcons.length; intCount++){
if(
objIcons[intCount].x > parseInt(objSelection.style.left) &&
objIcons[intCount].x < parseInt(objSelection.style.left) + parseInt(objSelection.style.width) &&
objIcons[intCount].y > parseInt(objSelection.style.top) &&
objIcons[intCount].y < parseInt(objSelection.style.top) + parseInt(objSelection.style.height)
)
{
document.getElementById(objIcons[intCount].id).style.border = "3px solid #316ac5";
document.getElementById(objIcons[intCount].id).style.margin = "-3px 0 0 -3px";
}
else {
document.getElementById(objIcons[intCount].id).style.border = "";
document.getElementById(objIcons[intCount].id).style.margin = "";
}
}
}
}
}
window.onmouseup = function() {
boolMouseDown = false;
var objSelection = document.getElementById(objSettings.id);
objSelection.style.display = "none";
}
Zuletzt bearbeitet von einem Moderator: