I have a carousel based off of:
http://nooshu.com/explore/jquery-iphone-animation/
When you are in the process of grabbing and dragging, you're apt to select text. If I have links in the panels, I get the hover message, etc...
I would like to disable all that, so when you are in the process of dragging, the rest of the interaction is disabled.
Ideas?
You'll need to call event. preventDefault() in both the down and move events in order to keep the browser from selecting text. Save this answer.
Another way to disable dragging an image is to set the pointer-event CSS property to none .
Create a style class like this:
.unselectable {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
-ms-user-select : none
}
Then alter the Javascript slightly to assign this class on mousedown. So from that unaltered script it would look like this.
jQuery(function($){
//Initialise
iPhoneAnimation.init();
//Mouse down bind move event
$(".content-box").bind("mousedown", function(e){
$(this).bind("mousemove", iPhoneAnimation.moveInfo);
$(this).addClass("unselectable"); // <-- ADD THIS
});
//Unbind mouse event
$(".content-box").bind("mouseup", function(e){
var $this = $(this);
$this.unbind("mousemove", iPhoneAnimation.moveInfo);
//Animate the panel
iPhoneAnimation.panelAnimate($this);
//Reset the private var
iPhoneAnimation.resetVars();
$(this).removeClass("unselectable"); // <-- AND ADD THIS
});
});
For disabling hovers you need to unbind the events on mousedown
like this:
$(this).unbind('mouseenter mouseleave');
Then rebind them again on mouseup
as above.
document.onmousemove = function(ev)
{
ev.preventDefault();
/*
move it
*/
}
I would complete Icchanobot's answer with one more line:
-ms-user-select : none
To make it work with Internet Explorer 11/-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With