In this article, we will share 8 super practical tips for jQuery users. jQuery is one of the best libraries for JavaScript. It is mainly used for animation and event processing, and supports Ajax and HTML script clients. In addition, jQuery also has various plug-ins to help developers quickly create websites/webpages in the shortest time.
I hope you will like these practical codes shared in this article.
1) Disable right-click function
If you want to save website information for users, then developers can use this code - disable right-click functionality.
//delete the default context menu
return false;
});
});
2) Use jQuery to set text size
Using this code, the user can resize the text (increase or decrease) according to their needs.
//Increase the text size
$(".increaseFont").click(function() {
var currentFontSize = $('html').css('font-size');
var currentFontSizeNumber = parseFloat(currentFontSize, 10);
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, 10);
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 the link in a new window
Using this code will help users open links in new windows and provide users with a better user experience.
4) Change style list
Use this code to help you change the style list.
5) Return to top link
This code is very useful for long-term clicks on a single page. You can click the "Return to Top" function at important junctures.
6) Get the X/Y axis of the mouse pointer
7) Detect current mouse coordinates
Using this script, you can get mouse coordinates in any web browser.
8) Image preloading
This code helps users load images or web pages quickly.