








Авиация
Сообщений 1 страница 10 из 134
Поделиться42023-01-16 05:55 pm
Код:
<div id="resizable" style="background-color: blue; width: 100px; height: 100px; position: relative;"></div>
<script>
let resizable = document.getElementById("resizable");
let handler = document.createElement("div");
handler.style.width = "100%";
handler.style.height = "10px";
handler.style.backgroundColor = "gray";
handler.style.position = "absolute";
handler.style.bottom = "0";
handler.style.cursor = "ns-resize";
resizable.appendChild(handler);
let startY, startHeight;
let isResizing = false;
resizable.addEventListener("mousedown", initDrag);
resizable.addEventListener("touchstart", initDrag);
handler.addEventListener("mousedown", initResize);
handler.addEventListener("touchstart", initResize);
function initDrag(e) {
if (isResizing) return; // prevent dragging when resizing
e.preventDefault();
let startX = e.clientX || e.touches[0].clientX;
let startY = e.clientY || e.touches[0].clientY;
let offsetX = resizable.offsetLeft;
let offsetY = resizable.offsetTop;
document.addEventListener("mousemove", drag);
document.addEventListener("touchmove", drag);
document.addEventListener("mouseup", stopDrag);
document.addEventListener("touchend", stopDrag);
function drag(e) {
let clientX = e.clientX || e.touches[0].clientX;
let clientY = e.clientY || e.touches[0].clientY;
let left = offsetX + clientX - startX;
let top = offsetY + clientY - startY;
if (left < 0) {
left = 0;
}
if (top < 0) {
top = 0;
}
if (left + resizable.offsetWidth > window.innerWidth) {
left = window.innerWidth - resizable.offsetWidth;
}
if (top + resizable.offsetHeight > window.innerHeight) {
top = window.innerHeight - resizable.offsetHeight;
}
resizable.style.left = left + "px";
resizable.style.top = top + "px";
}
function stopDrag() {
document.removeEventListener("mousemove", drag);
document.removeEventListener("touchmove", drag);
}
}
function initResize(e) {
isResizing = true; // set the flag to indicate that resizing is in progress
e.preventDefault();
startY = e.clientY || e.touches[0].clientY;
startHeight = resizable.clientHeight;
document.addEventListener("mousemove", resize);
document.addEventListener("touchmove", resize);
document.addEventListener("mouseup", stopResize);
document.addEventListener("touchend", stopResize);
}
function resize(e) {
let clientY = e.clientY || e.touches[0].clientY;
let newHeight = startHeight(clientY - startY);
if (newHeight < 0) {
newHeight = 0;
}
if (newHeight + resizable.offsetTop > window.innerHeight) {
newHeight = window.innerHeight - resizable.offsetTop;
}
resizable.style.height = newHeight + "px";
}
function stopResize() {
document.removeEventListener("mousemove", resize);
document.removeEventListener("touchmove", resize);
isResizing = false; // reset the flag to indicate that resizing has stopped
}
</script>
Поделиться52023-01-16 06:09 pm
Код:
jQuery(document).on('click touchstart mouseup', function(event) {
if (!jQuery(event.target).closest('.bb-popup, .chx-color-bb-prompt, .chx-image-bb-prompt, .chx-link-bb-prompt, .chxicon-plus').length && this.getSelection().toString() == "") {
jQuery('.bb-popup, .chx-color-bb-prompt, .chx-image-bb-prompt, .chx-link-bb-prompt').fadeOut("fast");
}
});Поделиться62023-01-16 06:13 pm
Код:
document.addEventListener("click", function(event) {
if (!event.target.closest('.bb-popup, .chx-color-bb-prompt, .chx-image-bb-prompt, .chx-link-bb-prompt, .chxicon-plus') && window.getSelection().toString() == "") {
let elements = document.querySelectorAll('.bb-popup, .chx-color-bb-prompt, .chx-image-bb-prompt, .chx-link-bb-prompt');
elements.forEach(function(element) {
element.style.display = "none";
});
}
});
Поделиться72023-01-16 08:37 pm
Код:
var chatx = document.getElementById("chatx");
var chx_header = document.querySelector(".chx_header");
chatx.addEventListener("mousedown", function(event) {
if (event.target === chx_header) {
event.preventDefault();
var mousePosition;
var offset = [
chatx.offsetLeft - event.clientX,
chatx.offsetTop - event.clientY
];
var windowWidth = window.innerWidth;
var windowHeight = window.innerHeight;
var chatxWidth = chatx.offsetWidth;
var chatxHeight = chatx.offsetHeight;
document.addEventListener("mousemove", function(event) {
mousePosition = {
x : event.clientX,
y : event.clientY
};
chatx.style.left = (mousePosition.x + offset[0]) + 'px';
chatx.style.top = (mousePosition.y + offset[1]) + 'px';
// containment
if (chatx.offsetLeft < 0) {
chatx.style.left = "0px";
}
if (chatx.offsetLeft + chatxWidth > windowWidth) {
chatx.style.left = windowWidth - chatxWidth + 'px';
}
if (chatx.offsetTop < 0) {
chatx.style.top = "0px";
}
if (chatx.offsetTop + chatxHeight > windowHeight) {
chatx.style.top = windowHeight - chatxHeight + 'px';
}
});
document.addEventListener("mouseup", function() {
document.removeEventListener("mousemove", null);
var chat_custom_position = {};
chat_custom_position[chatx.id] = {
left: chatx.offsetLeft,
top: chatx.offsetTop
};
localStorage.setItem("chat_custom_position", JSON.stringify(chat_custom_position));
});
}
});
Поделиться82023-01-17 12:27 am
Код:
document.querySelector('.bb-container').addEventListener('click', function(event) {
if (event.target.matches('.bb1')) {
bbtags("shoutbox-comment", "[b]", "[/b]");
} else if (event.target.matches('.bb2')) {
bbtags("shoutbox-comment", "[u]", "[/u]");
} else if (event.target.matches('.bb3')) {
bbtags("shoutbox-comment", "[i]", "[/i]");
} else if (event.target.matches('.bb4')) {
// Code to handle bb4
} else if (event.target.matches('.bb5')) {
// Code to handle bb5
} else if (event.target.matches('.bb6')) {
// Code to handle bb6
}
});
Поделиться92023-01-17 03:05 am
Код:
jQuery(".chx-color-bb-prompt").css({
height: height - 3
});
jQuery(".chx-image-bb-prompt, .chx-link-bb-prompt").fadeOut(0);
jQuery(".chx-color-bb-prompt").fadeIn(300);
Поделиться102023-01-17 03:09 am
Код:
document.querySelector(".chx-color-bb-prompt").style.height = height - 3 + 'px';
document.querySelectorAll(".chx-image-bb-prompt, .chx-link-bb-prompt").forEach(function(el){
el.style.display = 'none';
});
document.querySelector(".chx-color-bb-prompt").style.display = 'block';
Быстрый ответ
Похожие темы
| Космос | Обои для рабочего стола | 2025-01-03 |