Today, we'll share some useful tips and tricks for jQuery developers. JQuery is one of the best JavaScript libraries for simplifying animations, event handling, and client-side scripting that supports Ajax and HTML . The network has a large number of jQuery plug-ins to help create a Web site in a short period of time through simple and easy methods.
Today we have selected a few pieces of code that are very useful to our team of jQuery developers. Hopefully you'll be able to use the code in your next project.
1) No right button
When developing WEB applications, there are situations where you need to disable the right-click feature. With this code, the JQuery developer can disable the right mouse click on the Web page. The code is as follows:
$ (document). Ready (function () {
//catch The right-click context menu
$ (document). Bind ("ContextMenu", function (e) {
//warning prompt-optional
alert ("No right-clicking!");
Delete the default context menu, return false;});
2) Text Scaling
With the following code, the user can increase or scale the font size in the Web page with the following code:
$ (document). Ready (function () {
//find the current font size
var originalfontsize = $ (' html '). CSS (' font-size ');
//increase The text size
$ (". Increasefont"). Click (function () {
var currentfontsize = $ (' html '). CSS (' Font-size ');
var currentfontsizenumber = parsefloat (Currentfontsize, ten);
var newfontsize = currentfontsizenumber*1.2;
$ (' HTML '). CSS (' font-size ', newfontsize);
return false;
});
Decrease the Text Size
$ (". Decreasefont"). Click (function () {
var currentfontsize = $ (' html '). CSS (' Font-size ');
var currentfontsizenum = parsefloat (Currentfontsize, ten);
var newfontsize = currentfontsizenum*0.8;
$ (' HTML '). CSS (' font-size ', newfontsize);
return false;
});
Reset Font Size
$ (". Resetfont"). Click (function () {
$ (' HTML '). CSS (' font-size ', originalfontsize);
});
});
3 Open a link in a new window
Using this jQuery code, any link that the user clicks on your site will open in a new window. As follows:
$ (document). Ready (function () {
//select all anchor tags, that have http in the href
//and apply the Target=_blank
$ ("a[href^= ' http ')"). attr (' target ', ' _blank ');
};