Hice un control de paginación y noté que al hacer clic en los botones es muy fácil seleccionar accidentalmente las imágenes y el texto individuales. ¿Es posible prevenir esto?
Para aclarar la selección, me refiero a resaltar con el mouse. (Intente arrastrar el mouse de un lado de la pantalla al otro).
Si intenta resaltar el texto o los controles en esta cuadrícula, no podrá seleccionarlos. ¿Cómo se hace eso? Enlace
arrastrar y seleccionar tanto inicializar en un evento de mouse hacia abajo como actualizar en movimientos posteriores del mouse. Cuando maneje los eventos para comenzar a arrastrar, o para seguir el mouse, cancele el burbujeo del evento y anule el retorno predeterminado del navegador:
algo como esto en su comienzo arrastrando el mouse hacia abajo y mueva los controladores-
e=e || window.event; pauseEvent(e);
function pauseEvent(e){ if(e.stopPropagation) e.stopPropagation(); if(e.preventDefault) e.preventDefault(); e.cancelBubble=true; e.returnValue=false; return false; }Para arrastrar, está capturando los eventos mousedown y mousemove . (Y, con suerte, los eventos touchstart y touchmove también, para admitir interfaces táctiles).
Tendrás que llamar a event.preventDefault() tanto en los eventos de down como de move para evitar que el navegador seleccione texto.
Por ejemplo (usando jQuery):
var mouseDown = false; $(element).on('mousedown touchstart', function(event) { event.preventDefault(); mouseDown = true; }); $(element).on('mousemove touchmove', function(event) { event.preventDefault(); if(mouseDown) { // Do something here. } }); $(window.document).on('mouseup touchend', function(event) { // Capture this event anywhere in the document, since the mouse may leave our element while mouse is down and then the 'up' event will not fire within the element. mouseDown = false; });Esta es una publicación muy antigua. Puede que no responda exactamente a esa situación, pero uso CSS para mi solución:
-webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;