Display and hide comments and reference buttons with the mouse over WordPress.
Display, hide, reply, and reference Buttons over the mouse
Ideas and principles
The principle is simple. If you have read one or two pages or even more pages of the Jquery manual,
You can understand the following principles. Otherwise, skip to the code implementation area.
The idea is simple,
Place the reply and reference buttons in the desired place, and set the CSS style to display: none;
Bind the hover action in Jquery to the area where you want to hover the cursor and display the button
Is it easy? If I write a blog before, it will definitely end,
Okay, now that you want to teach fish, continue .......
Code Implementation of special effects
Reply to and reference HTML code
Copy codeThe Code is as follows:
<Div class = "comment-act"> <a href = "# respond"> reply </a> | <a href = "# respond"> reference </a> </div>
Reply and reference CSS style settings
. Comment-act {display: none;} Jquery (Javascript) Code Part Note: li. comment is the region where each comment is located $ ('Li. comment '). hover (// Note 1 function () {$ (this ). find ('div. comment-act '). fadeIn (400);}, function () {$ (this ). find ('div. comment-act '). fadeOut (400 );});
Code enhancement and advanced extension of special effects
Jquery special effects often encounter such a situation,
Some extreme users will switch back and forth continuously in two areas with Hover animation effects (for testing ?),
Because we usually set a display time for the special effect display. Here we set the display time to 400 milliseconds,
Obviously, the user's mouse switches back and forth for about 100 milliseconds, or even less,
When you switch back and forth, an animation queue is usually generated, even if you do not move your mouse,
The special effects will be hidden and displayed based on the actions you have taken before the mouse until you have responded to the last mouse action,
Although I am not familiar with this situation, if we have many comments,
But is it easy for a visitor to slide his or her mouse over and over the content?
Is it annoying?
This will not only increase the client browser load, but also affect website efficiency and improve user experience.
Solving the problem is actually very simple. Use hover's callback function parameters to terminate the animation queue,
$ ('Li. comment '). hover (// Note 1 function () {$ (this ). find ('div. comment-act '). fadeIn (400);}, function () {$ (this ). find ('div. comment-act '). fadeOut (400, function () {$ (this ). stop (true );});});
Because when we move the mouse, we want to stop all animation displays,
Therefore, we can stop the animation queue in this area after moving the mouse out of the hidden reply and reference buttons.
According to the test, so far, MG12's blog has not dealt with this situation (lazy? No need ?).
You can use his blog for comparison!
Note 1: hover is a method that imitates the hover event (move the mouse over an object and remove it. This is a custom method,
It provides a "Stay in it" status for frequently used tasks.
When you move the cursor over a matching element, the specified first function is triggered. When you move the cursor out of this element, the specified second function is triggered.
Show and hide comments
This feature is available in many themes to reduce page space and improve user experience. I have reserved this feature for this topic, but it has never been changed because I am lazy. Recently, I am still lazy when I add a new version to my blog. I feel that I am so idle that I don't have to worry about it.
High finger positive
The JS Code is as follows:
Var cmtinfo = jQuery ('# cmtinfo'); if (cmtinfo. length> 0) {var hideinfo = cmtinfo. find ('# hide_author_info'); var showinfo = cmtinfo. find ('# show_author_info'); var authorinfo = jQuery ('# author_info'); authorinfo. hide (); showinfo. click (function () {jQuery (this ). fadeOut (function () {hideinfo. fadeIn () ;}); authorinfo. fadeIn () ;}); hideinfo. click (function () {jQuery (this ). fadeOut (function () {showinfo. fadeIn () ;}); authorinfo. fadeOut ();});} # cmtinfo is a new DIV of the visitor displayed by the visitor with information # hide_author_info, # show_author_info. One is a hidden button, and the other is a display button # author_info is # A Sub DIV of cmtinfo
Articles you may be interested in:
- Implementation example of comments submission using AJAX technology in WordPress
- Optimize time display of articles and comments in WordPress
- Using AJAX to asynchronously retrieve comments to user portraits in WordPress
- Detailed description of PHP functions that call comment templates and output comments cyclically in WordPress
- WordPress restricts non-administrator users to comment only once after the article
- Describes the PHP functions used in WordPress to obtain comment templates and search forms.
- Solve the problem that WordPress cannot comment after using CDN
- Use jQuery to implement @ ID floating display of comments in WordPress
- Compile a PHP script to implement the comment paging function in WordPress
- Example of modifying the PHP script to enable WordPress to intercept spam comments
- Customize the default comment Avatar and delay loading in WordPress
- Some methods to optimize guest comment in WordPress