Because the user may have touch AND a mouse.
Include jQuery:
<scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Include plugin's code:
<scriptsrc="dist/both.min.js"></script>
Call the plugin:
both();
Add your mouse and touch events
// mouse$('.button-blue').on('mouseenter',function(){alert("Mickey");});// touch$('.button-blue').on('touchend',function(){alert("Tacchi");});$(window).data('both').store('mouse',$('.button-blue'),'mouseenter',function(e){alert("Mickey");});$(window).data('both').store('touch',$('.button-blue'),'touchend',function(e){alert("Tacchi");});Override default values [OPTIONAL]:
both({// touch screen (true) or not (false)touch: Modernizr.touch,// default: false// data attribute name (or class name prefix)name: null,// default: 'interaction'// data attribute (false) or class (true)class: true,// default: false});
- touch setting allows you to initialize the plugin with a presetted touch device (string)
- name setting allows you to change the default data attribute name by your own (or class prefix name if class is defined as true)
- class setting allows you to use a class instead of data attribute
If you use a device detection solution like device.js or a touch screen detection like [Modernizr(https://github.com/modernizr/modernizr), you can specify the screen type in touch option for not waiting the first tap on touch devices (default: false).
Set name at null or '' and class at true to deactivate class prefix (override useless Modernizr's 'touch' class which detects touch screens, no interaction type).
bower install both --save
| idomusha |