n('mousemove touchmove', function(e) { if (!isDragging) return; var clientX = e.type === 'touchmove' ? e.originalEvent.touches[0].clientX : e.clientX; var clientY = e.type === 'touchmove' ? e.originalEvent.touches[0].clientY : e.clientY; // 计算新位置 var newLeft = clientX - startX; var newTop = clientY - startY; // 限制在窗口范围内 var windowWidth = $(window).width(); var windowHeight = $(window).height(); var containerWidth = playerContainer.outerWidth(); var containerHeight = playerContainer.outerHeight(); newLeft = Math.max(0, Math.min(newLeft, windowWidth - containerWidth)); newTop = Math.max(0, Math.min(newTop, windowHeight - containerHeight)); // 应用新位置 playerContainer.css({ left: newLeft + 'px', top: newTop + 'px', right: 'auto', bottom: 'auto' }); e.preventDefault(); e.stopPropagation(); }); $(document).on('mouseup touchend', function() { if (isDragging) { isDragging = false; playerContainer.removeClass('dragging'); } }); } // 窗口大小变化时重新计算 $(window).resize(function() { if (!isFloating) { originalPosition = playerContainer.offset().top; } else { // 如果正在悬浮,确保播放器保持在可视范围内 var containerWidth = playerContainer.outerWidth(); var containerHeight = playerContainer.outerHeight(); var windowWidth = $(window).width(); var windowHeight = $(window).height(); var currentLeft = parseInt(playerContainer.css('left')); var currentTop = parseInt(playerContainer.css('top')); var newLeft = Math.max(0, Math.min(currentLeft, windowWidth - containerWidth)); var newTop = Math.max(0, Math.min(currentTop, windowHeight - containerHeight)); playerContainer.css({ left: newLeft + 'px', top: newTop + 'px' }); } }); }); -->